问题
I am trying to add links on my webpage to different locations on my google map. The map is two different kml files, one of the two is displayed to the user based on their zoom level. I have tried the traditional ways to add a link to a location in javascript but the link doesnt work. This is what I have right now:
google.maps.KmlMouseEvent.latlng(bathrooms_link, 'click', function(){
var bath = new google.maps.LatLng(38.04851723912264, -84.59609386082468);
});
map.panTo(bath);
回答1:
You can't access the information in a KmlLayer except by actually clicking on it (with an actual click), if you want to trigger a mouse event like you are, you need to provide all the rest of the information required in the mouse event (featureData, latLng, pixelOffset).
And you need to trigger the click event, not what you are doing.
Something like:
google.maps.event.trigger(layer, "click", {
latLng: new google.maps.LatLng(38.04851723912264, -84.59609386082468),
featureData:{},
pixelOffset: new google.maps.Size(0,0)
});
map.panTo(bath);
Haven't been able to make that work (and not sure it is worth doing so). Perhaps if your KML isn't very complex, investigate using a third party KML parser like geoxml3 or geoxml-v3, which render the KML using native Google Maps Javascript API v3 objects.
来源:https://stackoverflow.com/questions/22977035/html-link-to-location-on-kml-layer