[英]Dynamic kml google maps
我想使用kml創建一個Google Maps應用,並且我想根據用戶的縮放動態地創建kml文件。
類似於Google Earth,但在Google Maps中(縮放部分)
我嘗試使用markermanager和clusterer,但是我有太多的標記,並且在移動設備上的性能非常差,但是使用kml並不是問題,但是我可以一次顯示所有標記。
我試圖在kml文件中使用NetworkLink,但是我沒有得到任何參數,例如zoom或bounds(我正在使用php)
我知道可以用JavaScript完成
new google.maps.KmlLayer('mykmlgenerator.php?zoom='+zoom);
但我想避免那有什么辦法?
謝謝
我嘗試了這一點,才意識到使用Google Maps進行動態KML笨拙。 如果可以的話,使用Google Maps JavaScript API( https://developers.google.com/maps/documentation/javascript/ )將KML轉換為JSON並在地圖上創建標記會更容易。
首先,讓我清楚一點,如果您想使用動態KML,則OpenLayers比Google Maps更好。 接下來,我想提供一些簡單的JavaScript,供我們在OpenLayers中使用。 您應該嘗試使用它們,因為它也使用JavaScript庫。
在這里,我向您簡要介紹代碼的編寫方式。
<html>
<head>
<title>Google Layer with KML file</title>
<link rel="stylesheet" href="http://openlayers.org/api/theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css" />
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAl9RMqSzhPUXAfeBCXOussRTQDbvAygy0cfGJr8dEMAYKf3RWNBQqP9mjKIsqTfmAlz5LOJ3Xpy5s4w'></script>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
// Create the map object
map = new OpenLayers.Map('map');
// Create a Google layer
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
// Add layer to map
map.addLayer(gmap);
//Adding KML file to map
map.addLayer(new OpenLayers.Layer.GML("KML", "yourkml.kml",
{
format: OpenLayers.Format.KML,
formatOptions: {
extractStyles: true,
extractAttributes: true,
maxDepth: 2
}
}));
// Zoom to Kuala Lumpur, Malaysia
map.setCenter(new OpenLayers.LonLat(101.686855,3.139003), 13);
}
</script>
</head>
<body onload="init()">
<h1 id="title">Google Layer with KML file</h1>
<div id="map" style='width: 700px; height: 700px'></div>
</body>
</html>
如您所見,地圖上有一個小的橙色圓點。 那就是加載在Google Maps上的KML文件。 如果要刷新它們,請檢查此鏈接
最后但並非最不重要的一點,我希望我的回答對您來說還為時不晚。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.