问题
This is the below code for displaying map according to kml .
var myLatLng = new google.maps.LatLng(41.875696, -87.624207);
var mapOptions = {
zoom: 11,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var ctaLayer = new google.maps.KmlLayer('http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml');
ctaLayer.setMap(map);
What i need is using the parse kml to show it on map.I will embed the kml data in string and pass to api to show it on map.
I dont want the kml to be fetched from url or from any file .I just want to embed kml in this page itself. Is it possible to do so ?
回答1:
The geoxml3 third party parser has a parseKmlString method which will take a string containing KML and render it on a Google Maps API v3 map as native Google Maps API v3 objects (not a KmlLayer, so you lose the benefit of tile based rendering, that KmlLayer gives you). Might meet your requirements (will depend on how complex your KML is).
来源:https://stackoverflow.com/questions/14653450/google-map-kml-implementation