Ralph wrote:
> Hi
>
> As in topic.
>
> I have tree tables:
> zipcodes_tbl with columns - zipcode, latitude, longitude,
> points_tbl - id, latitude, longitude
> destinations_tbl - zipcode, point_id
>
> I also have SP called distance that takes 4 arguments (a_lat, a_lon,
> b_lat, b_lon) and gives me distance between two points.
>
> Is it possible without using Cursors (probably nested ones) to insert
> data to destinations_tbl storing zipcodes and all points within lets say
> 50miles radius.
>
> Thank you
From:
http://jehiah.com/archive/spatial-pr...using-latlongs
CREATE TABLE `zip` (
`zip` varchar(12) NOT NULL DEFAULT '',
`latitude` float NOT NULL DEFAULT '0',
`longitude` float NOT NULL DEFAULT '0',
`city` varchar(50) DEFAULT NULL,
`state` varchar(50) DEFAULT NULL,
`county` varchar(50) DEFAULT NULL,
`zip_class` varchar(50) DEFAULT NULL,
PRIMARY KEY (`zip`)
);
SELECT user_id
FROM users, zip_codes
WHERE users.zip = zip_codes.zip
AND degrees(acos(
sin( radians(zip_codes.latitude) )
* sin( radians(47.604718))
+ cos( radians(zip_codes.latitude))
* cos( radians(47.604718))
* cos( radians(zip_codes.longitude - -122.335230) )
) ) * 69.09 < 50
This is one example of how it has already been done. Figuring out how to apply
it is an excercise for the OP.
--
Michael Austin.
Database Consultant