如何动态创建带有kml图层叠加层的Google地图 [英] How to create a google map with kml layer overlay dynamically

查看:208
本文介绍了如何动态创建带有kml图层叠加层的Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  function initialize(){
var myOptions = {
center:new google.maps.LatLng(23.71181,90.407467),
zoom:8 ,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map_canvas),
myOptions);
var map_coverage = new google.maps.KmlLayer('http://mydomain.com/myfile.kmz');
map_coverage.setMap(map);
map.setZoom(12);
map.setCenter(dhaka_latlng);

以上代码使用kmllayer输出以下地图,并且已创建kml文件Google地球并将其保存为服务器上的kmz(压缩)文件。此文件包含一些xml数据,彩色区域代表标记中的一些坐标以及其他标记,如

 < coordinates> 
90.27401489730001,23.9502580159,0 90.2740186914,23.95007761100001 ...等等
< / coordinates>

我想使用javascript api-v3动态地创建一个类似kmllayer的地图,但没有Google earth的帮助。我的意思是我想用php创建kml文件并将其作为somefile.kmz保存在服务器上。那可能吗 ?任何形式的帮助将不胜感激。谢谢!



如果您需要,我可以发布原始kml文件,但它很大

解决方案

是的,可以生成一个新的KML文件服务器端(PHP),然后告诉JavaScript使用生成KML内容的URL加载新的KmlLayer 。请注意,由于Google服务器需要下载,所以KML网址:


  • 必须是公开的。

  • 将被Google服务器缓存,在同一个网址提供不同的内容不会刷新它。



为了克服这种缓存,在网址中添加一些随机的咔嗒声。但是,请注意缓存可以使其更快。您不能同时拥有超快KML和实时新数据。此外,请注意您自己的服务器对KML网址的响应时间,越快越好。


function initialize() {
    var myOptions = {
      center: new google.maps.LatLng(23.71181,90.407467),
      zoom: 8,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    var map_coverage = new google.maps.KmlLayer('http://mydomain.com/myfile.kmz'  );
    map_coverage.setMap(map);       
    map.setZoom(12);
    map.setCenter(dhaka_latlng);    
  }

Above code outputs the following map with kmllayer and the kml file has been created with Google earth and saved as a kmz (compressed) file on the server. This file contains some xml data and the colored area represents some coordinates in a tag along with other tags like

<coordinates>
    90.27401489730001,23.9502580159,0 90.2740186914,23.95007761100001 ... so on
</coordinates>

I want to dynamically create a similar map with kmllayer using javascript api-v3 but without help of Google earth. I mean i want to create kml file using php and save it on the server as somefile.kmz. Is that possible ? Any kinds of help will be appreciated. Thanks !

I can post the original kml file if you need but it's to large

解决方案

Yes, it is possible to generate a new KML file server-side (PHP) and then tell JavaScript to load a new KmlLayer using the URL that will generate the KML content. Note that the KML URL:

  • must be publicly accessible, since Google servers need to download it
  • will be cached by Google servers, serving a different content at the same URL won't refresh it

To overcome this caching, just add some random clatter to the URL. However, be aware caching is there to make it fast. You can't have both "super-fast KML" and "real-time fresh data" at once. Also, keep an eye on your own server's response times for KML URLs, the faster the better.

这篇关于如何动态创建带有kml图层叠加层的Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆