我正在编写一段javascript,使用geolocation api检索用户的位置,并使用google maps api将其显示在地图上。我写了下面的代码。它似乎在本地工作正常,但只要我在我的网站上托管代码,就会有一个更长的用户位置提示(http://lucakleijweg.nl/myLoc.html)。你能帮我找出原因吗?
//getting the user's location
window.onload = getMyLocation();
function getMyLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(displayLocation, displayError);
} else {
alert ("oops, no geolocation support");
}
}
function displayLocation(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var div = document.getElementById("location");
div.innerHTML = "you are at Latitude:" + latitude + ", Longitude:" + longitude;
div.innerHTML += " (with " + position.coords.accuracy + " meters accuracy)";
//calculate distance from HQ using user's coordinates
var km = computeDistance(position.coords, ourCoords);
var distance = document.getElementById("distance");
distance.innerHTML = "you are " + km + " km away from the Wickedly Smart HQ";
showMap(position.coords);
}
答案 0 :(得分:0)