Google Maps Javascript API v3中的KML图层问题 [英] KML layer problems in Google Maps Javascript API v3
问题描述
以下是我的代码:
< html>< head>
< meta name =viewportcontent =initial-scale = 1.0,user-scalable = no/>
< style type =text / css>
html {height:100%}
body {height:100%;保证金:0; padding:0}
#map-canvas {height:500px;宽度:500px; }
< / style>
< title>映射您的代表< / title>
< script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?key = {key}>< / script>
< script type =text / javascript>
函数initialize(){
var mapOptions = {
center:new google.maps.LatLng(-34,92),
zoom:7
};
var map = new google.maps.Map(document.getElementById(map-canvas),mapOptions);
var kmlUrl =http:// {HOST} /kml/file.kml;
var kmlOptions = {
suppressInfoWindows:true,
preserveViewport:false,
map:map
};
var kmlLayer = new google.maps.KmlLayer(kmlUrl,kmlOptions);
}
google.maps.event.addDomListener(window,'load',initialize);
< / script>
< / head>
< body>
< h1>地图< / h1>
< div id =map-canvas/>
< / body>< / html>
由于某些原因,.kml文件虽然可公开访问,但不会被API加载。
我注意到Chrome中的开发人员工具的网络标签中包含以下请求:
https://maps.googleapis.com/maps/api/js/KmlOverlayService.GetOverlays?1shttp%3A%2F%2F {HOST}%2Fkml%2Ffile.kml&安培;回调= _xdc _._ 9dx071&安培;标记= 97074
回应是:
/ ** / _ xdc_。 _9dx071&& _xdc __ 9dx071([0,null,null,null,null,null,3,[[client,2]]])
当我加载其他KML文件时,此数据结构表示来自文件的数据。
一些事实:
非常感谢所有帮助,我可以弄清楚为什么这个KML层没有加载。
谢谢! / p>
我遇到了同样的问题(响应中为空)。事实证明,我通过服务器上的iptables阻止了Google。
Here's my code:
<html><head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 500px; width: 500px; }
</style>
<title>Map Your Reps</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api /js?key={key}"></script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34, 92),
zoom: 7
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var kmlUrl = "http://{HOST}/kml/file.kml";
var kmlOptions = {
suppressInfoWindows: true,
preserveViewport: false,
map: map
};
var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<h1>Map</h1>
<div id="map-canvas"/>
</body></html>
For some reason, the .kml file, though publicly accessible, is not getting loaded by the API.
I notice in the network tab of the developer tools in Chrome the following request:
https://maps.googleapis.com/maps/api/js/KmlOverlayService.GetOverlays?1shttp%3A%2F%2F{HOST}%2Fkml%2Ffile.kml&callback=_xdc_._9dx071&token=97074
The response is:
/**/_xdc_._9dx071 && _xdc_._9dx071( [0,null,null,null,null,null,3,[["client","2"]]] )
When I load other KML files, this data structure represents the data from the file.
Some facts:
- My HTML file and my KML file are both on an Amazon EC2 instance and accessible publicly ... no passwords, HTTPS, or other tricky business
- My KML file is not compressed ... it's a real-life bonafide KML file
- My KML file validates on kmlvalidator.com
- My KML is 709K in size and includes polygons
- No error messages are generated, and nothing appears on the map ... except the map itself.
I'd appreciate any assistance I can get to figure out why this KML layer isn't loading.
Thanks!
I was having the same problem (nulls in the response). It turns out I was blocking google via iptables on the server.
这篇关于Google Maps Javascript API v3中的KML图层问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!