开发者

google maps API geocode finds nearby KML

开发者 https://www.devze.com 2023-02-05 17:53 出处:网络
I\'ve seen a number of people ask about this on Google Maps discussion groups to productive discussion, so I thought I would try here.

I've seen a number of people ask about this on Google Maps discussion groups to productive discussion, so I thought I would try here.

Goal: make a searchable map in Google Maps API that can return "nearby" results from a dataset when a user address is entered.

My approach so far: I started by putting my datapoints into KML since it is both a) easily used by Google Maps API, and b) an XML document, and so easy to traverse. As I understand it, the Geocode method is the API's basic point of entry for any sort of user geographic information. I figured I would have to get Geocode to return a Lat and Long, then calculate the distance between this point and every Placemark in the KML file using a Haversine formula, and finally display the point the shortest distance from the user's Lat and Long.

I've seen a bit of Javascript out there that runs a Haversine calculation, but am unclear on how to get the API to r开发者_开发知识库ead all the datapoints in a KML file. Google put up a helpful doc about how to do this with PHP and a MySQL db, but doesn't help too much with the KML situation.

So: how to get Google Maps API to search and parse KML?

Thanks!


You can't access the elements inside KML in Maps API V3. All you can do is to download your KML, with XMLHttpRequest and parse and traverse like any other XML. Then calculate distance, and you can display your markers from code.

0

精彩评论

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

关注公众号