google map kml implementation

 ̄綄美尐妖づ 提交于 2020-05-12 07:18:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!