我使用 Processwire 创建了一个网站,并包含了一个自定义样式的 Google 地图,其中包含来自 xml 文件的多个标记。在桌面上,它就像魅力一样。当我使用 Browserstack 时,即使是手机也能正确显示。但现实生活中,手机(Android 和 iOs)不会显示标记(.png)。
有人可以帮忙吗?
这是我的代码:
var xmlFile = 'http://website.ch/adressen.xml/';
var icons = {
1: {
icon: 'http://website.ch/site/templates/img/marker.png'
}
};
function initMap() {
var styledMapType = new google.maps.StyledMapType(
[
some styles for the map...
], {
name: 'MapName'
});
var switzerland = new google.maps.LatLng(46.82235, 8.40440);
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
var map = new google.maps.Map(document.getElementById('map'), {
center: switzerland
, zoom: 7
, mapTypeControlOptions: {
mapTypeIds: []
}
});
} else {
var map = new google.maps.Map(document.getElementById('map'), {
center: switzerland
, zoom: 8
, mapTypeControlOptions: {
mapTypeIds: ['styled_map']
}
});
}
map.mapTypes.set('styled_map', styledMapType);
map.setMapTypeId('styled_map');
var infoWindow = new google.maps.InfoWindow;
downloadUrl(xmlFile, function (data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function (markerElem) {
var id = markerElem.getAttribute('id');
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('address');
var city = markerElem.getAttribute('city');
var link = markerElem.getAttribute('link');
var type = markerElem.getAttribute('type');
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var street = document.createElement('text');
street.textContent = address
infowincontent.appendChild(street);
infowincontent.appendChild(document.createElement('br'));
var place = document.createElement('text');
place.textContent = city
infowincontent.appendChild(place);
infowincontent.appendChild(document.createElement('br'));
infowincontent.appendChild(document.createElement('br'));
var a = document.createElement('a');
a.setAttribute('href', link);
a.setAttribute('target', '_blank');
a.innerHTML = 'Website';
infowincontent.appendChild(a);
var marker = new google.maps.Marker({
map: map
, position: point
, icon: icons[type].icon
});
marker.addListener('click', function () {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}
function downloadUrl(url,callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}