proximity search google map

2019-04-01 02:20发布

问题:

I am using google map v3 to capture all the addresses in a MS SQL database table called Locations which will have columns like LocationName, LocationAddress, LocationZip, LocationState, LocationCity, LocLatitude, LocLongitude and LocationType(like hospital, physician office or emergency centers etc)..

I have an input box where users can search by keyword and a dropdown with 5,10, 20 and 50 miles radius option. I have been able to use the input box and pass the typed keyword as querystring to search for all the matching location and plot markers for them in google map api 3. I also like to do proximity search on the matched results like withing 5 miles of say Los Angeles..

can the method used in this site be used ? http://maps.huge.info/dragcircle2.htm

It is drawing a radius withing 5 miles, I need to pretty much capture all the markers within that radius? Please some genius google map guys/girls give me some guidance..

回答1:

Google has a complete tutorial on creating a store locator. The vital piece of information that you are missing is how to query your database to pull back the locations within your radius.

http://code.google.com/apis/maps/articles/phpsqlsearch.html

take a look at the link above for details but the query will look somthing like this (mySQL):

SELECT
  address,
  name,
  lat,
  lng,
  (
    3959 * acos(
      cos( radians('%s') ) * cos( radians( lat ) )
      *
      cos( radians( lng ) - radians('%s') )
      +
      sin( radians('%s') )
      *
      sin( radians( lat ) )
    )
  ) AS distance 
FROM markers 
HAVING distance < '%s' 
ORDER BY distance 
LIMIT 0 , 20

It uses trigonometry!