在不同站点上使用时不显示 KMZ 层
KMZ layer not showing when using on a different site
所以我在我的网站上显示了一个 KMZ 层,但不会在其他任何地方显示。
这是我的 Javascript:
function getBaseUrl() {
var e = RegExp(/^.*\//);
return e.exec(window.location.href);
}
function initialize() {
function e() {
navigator.geolocation.getCurrentPosition(function(e) {
var o = new google.maps.LatLng(e.coords.latitude, e.coords.longitude);
p ? p.setPosition(o) : p = new google.maps.Marker({
position: o,
icon: "http://i.imgur.com/1VTzeOS.png",
map: map
}), map.setCenter(t);
}), setTimeout(e, 3e5);
}
var o = new google.maps.LatLng(42.449686, -71.230919), t = o, a = {
zoom: 12,
center: o,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), a), geoXml = new geoXML3.parser({
map: map,
singleInfoWindow: !0,
zoom: !1
}), geoXml.parseKmlString(kmlData);
for (var n = {
path: "M 0,-1 0,1",
strokeOpacity: 1,
scale: 2.5,
preserveViewport: !0
}, i = 0; i < geoXml.docs[0].gpolylines.length; i++) geoXml.docs[0].gpolylines[i].setOptions({
strokeOpacity: 1,
strokeWeight: 1,
zoom: !1,
icons: [ {
icon: n,
offset: "0",
repeat: "1px"
} ]
});
var r = new google.maps.KmlLayer({
url: parent + "parking2.kmz",
strokeWeight: 20,
strokeOpacity: 0,
preserveViewport: !0
});
r.setMap(map);
var p = (new google.maps.InfoWindow({
content: "You are here!"
}), null);
e();
}
var parent = getBaseUrl();
google.maps.event.addDomListener(window, "load", initialize);
parking2.kmz 层将不会显示在例如 127.0.0.1/localhost 上 xampp 或 http://example.com/test/map.html. It will however show on http://example.com/map.html。有什么想法吗?
Geoxml3 使用 xmlHttpRequest 对象检索 KML/KMZ。这受同源策略的约束。您只能从完全相同的域访问 KML/KMZ。相对 URL 应该可以工作,或者您可以使用代理来访问其他域上的数据。
google.maps.KmlLayer
只能显示公开可用KML/KMZ(KML/KMZGoogle的服务器可以访问),所以不适用于本地主机 (127.0.0.1/localhost)。
KML and GeoRSS Layers
: Overview
The Google Maps JavaScript API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file.
相关:
-
所以我在我的网站上显示了一个 KMZ 层,但不会在其他任何地方显示。 这是我的 Javascript:
function getBaseUrl() {
var e = RegExp(/^.*\//);
return e.exec(window.location.href);
}
function initialize() {
function e() {
navigator.geolocation.getCurrentPosition(function(e) {
var o = new google.maps.LatLng(e.coords.latitude, e.coords.longitude);
p ? p.setPosition(o) : p = new google.maps.Marker({
position: o,
icon: "http://i.imgur.com/1VTzeOS.png",
map: map
}), map.setCenter(t);
}), setTimeout(e, 3e5);
}
var o = new google.maps.LatLng(42.449686, -71.230919), t = o, a = {
zoom: 12,
center: o,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), a), geoXml = new geoXML3.parser({
map: map,
singleInfoWindow: !0,
zoom: !1
}), geoXml.parseKmlString(kmlData);
for (var n = {
path: "M 0,-1 0,1",
strokeOpacity: 1,
scale: 2.5,
preserveViewport: !0
}, i = 0; i < geoXml.docs[0].gpolylines.length; i++) geoXml.docs[0].gpolylines[i].setOptions({
strokeOpacity: 1,
strokeWeight: 1,
zoom: !1,
icons: [ {
icon: n,
offset: "0",
repeat: "1px"
} ]
});
var r = new google.maps.KmlLayer({
url: parent + "parking2.kmz",
strokeWeight: 20,
strokeOpacity: 0,
preserveViewport: !0
});
r.setMap(map);
var p = (new google.maps.InfoWindow({
content: "You are here!"
}), null);
e();
}
var parent = getBaseUrl();
google.maps.event.addDomListener(window, "load", initialize);
parking2.kmz 层将不会显示在例如 127.0.0.1/localhost 上 xampp 或 http://example.com/test/map.html. It will however show on http://example.com/map.html。有什么想法吗?
Geoxml3 使用 xmlHttpRequest 对象检索 KML/KMZ。这受同源策略的约束。您只能从完全相同的域访问 KML/KMZ。相对 URL 应该可以工作,或者您可以使用代理来访问其他域上的数据。
google.maps.KmlLayer
只能显示公开可用KML/KMZ(KML/KMZGoogle的服务器可以访问),所以不适用于本地主机 (127.0.0.1/localhost)。
KML and GeoRSS Layers : Overview
The Google Maps JavaScript API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file.
相关: -