开发者

google maps api issue: retrieving list of markers within map generated by user search

i have the following scenario: 1. i will keep a list of stores locations (coordinates and info) 2. will "feed' relevant info from that list to Google map objec开发者_JAVA技巧t 3. the user can search for stores around a given radius from their home 4. the generated map will display markers of stores if any are found.

so far, i'm good.. NOW: after such a map has been generated and markers placed in it, how can i retrieve (hopefully from the Google object) a list of all included stores/markers ? -- the idea here is that my client wants to store the users' address along with the stores close to their home.

any help would be highly appreciated, thanx in advance


eventually i tackled the issue from another direction: 1. get lat & lng of user's address using geo.getLocations 2. check distance from all stores in Db (lat lng already stored in Db) using a php function 3. write link in html for each store that's within desired radius 4. link opens a window with google map containing address and store location as markers

long story short: First crate the list, THEN display maps.. = no need to try extract data from the map.

i guess there are better ways to go about it - this one did it for me.. i will gladly submit the code in detail to anyone interested. it involves combination of js, php and some jquery ajax.


You want to look for the harvesine formula. The harvesine formula can compute the distance between 2 points. If you can do a query nested with the harvesine formula you select all stores within a given radius.


I would do this:

//points is an array of LatLng items

var bounds = map.getBounds()

for (i=0,len=points.length;i<len;i++) {
  if (bounds.contains(points[i])) {
    //do your stuff with the visible item
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜