[英]Unable to render KML file into google map
My Google map code 我的Google地图代码
var myOptions = {
center: {lat: 55.864237, lng: -4.251806},
zoom: 16,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map1 = new google.maps.Map(document.getElementById("map"), myOptions);
var geoXml = new geoXML3.parser({
map: map1
});
var source = 'https://developers.google.com/kml/documentation/KML_Samples.kml';
geoXml.parse(source);
And the error i am getting is as follows: 我得到的错误如下:
Failed to load https://developers.google.com/kml/documentation/KML_Samples.kml : No 'Access-Control-Allow-Origin' header is present on the requested resource. 无法加载https://developers.google.com/kml/documentation/KML_Samples.kml :所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:8080 ' is therefore not allowed access. 因此,不允许访问源' http:// localhost:8080 '。
XML parse error Unable to retrieve https://developers.google.com/kml/documentation/KML_Samples.kml XML解析错误无法检索https://developers.google.com/kml/documentation/KML_Samples.kml
Anyone knows how can i solve this issue? 谁知道我该如何解决这个问题?
GeoXml3 uses the browser's XmlHttpRequest object, which is subject to the same origin policy . GeoXml3使用浏览器的XmlHttpRequest对象,该对象遵循相同的原始策略 。 You can't access https://developers.google.com
from http://localhost:8080
(different origins). 您无法从http://localhost:8080
(不同的来源)访问https://developers.google.com
。
To use GeoXml3, either copy that file to your server and access it through a relative URL or access it through a proxy on http://localhost:8080
. 要使用GeoXml3,请将该文件复制到您的服务器并通过相对URL进行访问,或者通过http://localhost:8080
上的代理进行访问。
example loading that URL through a proxy 通过代理加载该URL的示例
example using the proxy
property of GeoXml3 使用GeoXml3的proxy
属性的示例
Another option would be to use the Google Maps Javascript API v3 KmlLayer
, which accesses the KML from Google's servers and isn't subject to the same origin policy. 另一个选择是使用Google Maps Javascript API v3 KmlLayer
,它可以从Google的服务器访问KML,并且不受同一来源政策的约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.