我的网站 www.procomport.com 仅适用于 Google Chrome 和 Firefox。
每次我用我的所有代码发布一个问题时,每个人都会大喊大叫说他们需要发布代码你还想从我这里得到什么!?JS 在 Chrome 和 Firefox 中完美运行,但仅此而已。
Javascript
var geocoder;
var map;
var lat1;
var lng1;
var lat2;
var lng2;
var range;
var htmlcard;
var initialLocation;
var measure;
function initialize() {
var siberia = new google.maps.LatLng(34.0522, -118.2428);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag = new Boolean();
var address = document.getElementById("addressForm");
//alert(address.value.trim().length);
//alert(address.value.length);
if (address.value.length <= 2) {
if (navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//createMap2(initialLocation);
load(initialLocation);
lat1 = position.coords.latitude;
lng1 = position.coords.longitude;
}, function () {
handleNoGeolocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
//alert("Failed to find location.");
//createMap(newyork);
load(newyork);
} else {
//alert("Your browser doesn't support geolocation. We've placed you in Los Angeles.");
//createMap(siberia);
load(siberia);
}
}
}
else {
geocoder = new google.maps.Geocoder();
var address = document.getElementById("addressForm").value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
load(results[0].geometry.location)
lat1 = results[0].geometry.location.lat();
lng1 = results[0].geometry.location.lng();
}
});
}
}
function load(center) {
range = document.getElementById("distance").value;
if (range == "" || range == 0)
{
range = "200";
}
measure = document.getElementById("measure").value;
if (measure !== "m") {
measure == "km";
}
geocoder = new google.maps.Geocoder();
var mapOptions1 = {
zoom: 12,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions1);
var marker = new google.maps.Marker({
map: map,
position: center
});
var professionFilter = document.getElementById("professionFilterValue").value;
//alert(professionFilter);
downloadUrl("xml.php?p=" + professionFilter, function (data) {
var xml = data.responseXML; // xml file generated from xml.php
var markers = xml.documentElement.getElementsByTagName("marker"); // parses XML and gets Markers From Data
for (var i = 0; i < markers.length; i++) {
// Sets infoWindow for specific marker
var infoWindow = new google.maps.InfoWindow({ maxwidth: 350 });
google.maps.event.addListener(map, "click", function () { infoWindow.close(); });
//=========================================================================================
// Sets Marker Attributes an Location
lat2 = markers[i].getAttribute("lat");
lng2 = markers[i].getAttribute("lng");
var distance = getDistance(lat1, lng1, lat2, lng2)
var display_name = markers[i].getAttribute('dname')
var card = markers[i].getAttribute('card')
var htmlCard = decodeURIComponent(card)
if (getDistance(lat1, lng1, lat2, lng2) < range) {
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = htmlCard
var icon = "https://www.procomport.com/site/www/images/computericon.png"
var marker = new google.maps.Marker({
map: map,
position: point,
icon: "/site/www/images/computericon.png",
shadow: icon.shadow,
title: name
});
bindInfoWindow(marker, map, infoWindow, html);
}
}
//=========================================================================================
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function () {
setTimeout(function () { infoWindow.setContent(html); }, '1000');
setTimeout(function () { infoWindow.open(map, marker); }, '1000');
setTimeout(function () { infoWindow.close(); }, '5000');
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() { }
function getDistance(lat11, lon11, lat22, lon22) {
var R;
if (measure == "km") {
R = 6371;
}
else {
R = 3959;
}
// km (change this constant to get miles)
var dLat = (lat22 - lat11) * Math.PI / 180;
var dLon = (lon22 - lon11) * Math.PI / 180;
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
if (d > 1) return Math.round(d);
else if (d <= 1) return Math.round(d * 1000);
return d;
}
就像我真的失去理智我做错了什么我运行了 W3 验证器,我被告知并修复了很多错误(元标记除外) 验证器结果
还需要哪些其他代码来准确诊断此问题?
Internet Explorer 控制台输出。
HTML1114: Codepage iso-8859-1 from (META tag) overrides conflicting codepage windows-1252 from (META tag)
map.php
HTML1514: Extra "<body>" tag found. Only one "<body>" tag should exist per document.
map.php, line 154 character 1
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead.
map.php, line 322 character 9
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead.
map.php, line 524 character 164
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead.
map.php, line 524 character 343
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead.
map.php, line 525 character 120
Invalid App Id: Must be a number or numeric string representing the application id.
更新:
修复了所有 IE 错误 - 仍然没有标记
更新 2:
每次我清除浏览器缓存并重新加载它工作正常的页面时都会取得一些进展。
更新 3:
地图甚至无法在 Safari 上加载