问题
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 read 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!
回答1:
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.
来源:https://stackoverflow.com/questions/4718451/google-maps-api-geocode-finds-nearby-kml