在谷歌地图上使用 KML / KMZ
为了进行测试,我将此 html 文件保存到我的服务器上。有没有一种简单的方法可以在此处包含 KML 或 KMZ 文件?
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABCDEFghijetc&sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(59.082089,5.649456), 18, G_SATELLITE_MAP);
map.setUIToDefault();
}
}
</script> </head> <body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 800px; height: 600px"></div> </body> </html>
To test I saved this html file to my server. Is there a simple way to include a KML or KMZ file here?
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABCDEFghijetc&sensor=false"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(59.082089,5.649456), 18, G_SATELLITE_MAP);
map.setUIToDefault();
}
}
</script> </head> <body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 800px; height: 600px"></div> </body> </html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将以下 JavaScript 添加到您的 init 函数中:
请注意,KML 必须是可公开访问的 URL,并且有大约 10MB 的限制:
https://developers.google.com/kml/documentation/mapsSupport
Try adding the following JavaScript to your init function:
Note the KML must be a publically accessible URL, and there is a ~10MB limit:
https://developers.google.com/kml/documentation/mapsSupport
您必须将 KML 线串 转换为 < a href="http://code.google.com/apis/maps/documentation/overlays.html#Drawing_Polylines" rel="nofollow noreferrer">Gmap Polyline 这将涉及一些手动数据操作,或 XML 解析器。
您还可以尝试这个在线转换工具。
You'll have to covert a KML linestring to a Gmap Polyline which will involve a little bit of manual data manipulation, or an XML parser.
You could also try this on-line conversion tool.