私はMySQLのジオ検索のためにこの例に従っています(本当に素晴らしいチュートリアルです!)。
これは私が思いついたものです:
CREATE DEFINER=`root`@`localhost` PROCEDURE `geo_distance`(in _location_id bigint(20), in dist int)
BEGIN
declare mylon double;
declare mylat double;
declare lon1 float;
declare lon2 float;
declare lat1 float;
declare lat2 float;
-- get the original lon and lat for the userid
select longitude, latitude into mylon, mylat from locations where locations.location_id = _location_id;
-- calculate lon and lat for the rectangle:
set lon1 = mylon - dist / abs(cos(radians(mylat)) * 69);
set lon2 = mylon + dist / abs(cos(radians(mylat)) * 69);
set lat1 = mylat - (dist / 69);
set lat2 = mylat + (dist / 69);
-- run the query:
SELECT destination.*,
3956 * 2 * ASIN(SQRT(POWER(SIN((orig.lat - dest.lat) * pi()/180 / 2), 2) +
COS(orig.lat * pi()/180) * COS(dest.lat * pi()/180) * POWER(SIN((orig.lon -dest.lon) * pi()/180 / 2), 2) )) as distance FROM locations destination, locations origin WHERE origin.location_id=_location_id
and destination.longitude between lon1 and lon2 and destination.latitude between lat1 and lat2
having distance < dist ORDER BY Distance limit 10;
END
問題は、彼が何をどこで取ったのかわからないことorig.lat
です。おそらく私は何かが足りないのでしょう。私の間違いを指摘したり、MySqlでの地理検索の良い情報源を提案したりできますか