【发布时间】:2012-10-22 20:06:30
【问题描述】:
好的,我正在为我的网站使用 Google Maps API,并且正在使用“设置当前位置”功能。
它对某些用户来说很好,但对于其他用户来说,它默认为“错误”的位置。
示例 1 我在利物浦的学生宿舍里找了一个朋友来测试这个网站。 当他允许当前位置时,它会将他的位置设置为他在斯塔福德的家,这是很远的。
示例 2 在使用大学计算机时,我测试了网站并允许使用当前位置功能。这一次,它将位置设置为大学服务器所在的建筑物,而不是计算机的位置(在利物浦的另一边!)
我对 IP 地理位置了解不够,所以想不出解决方案,也找不到任何类似的 stackoverflow 问题。 有没有办法以更准确的方式设置位置?也许我可以使用邮政编码设置位置?
任何帮助将不胜感激。
特里斯坦
编辑: 这是我在初始化函数中设置位置的代码
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(currentPositionCallback);
} else {
alert('The browser does not support geolocation');
}
function currentPositionCallback(position) {
// Create a new latlng based on the latitude and longitude from the users position
var user_lat_long = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Add a marker using the user_lat_long position
var userpos = new google.maps.Marker({
position: user_lat_long,
icon: new google.maps.MarkerImage("img/icons/icon_home.png", new google.maps.Size(32, 34)),
map: map
});
// Set the center of the map to the users position and zomm into a more detailed level
map.setCenter(user_lat_long);
map.setZoom(15);
}
【问题讨论】:
-
你试过 Txugo 的答案了吗?:stackoverflow.com/questions/2851089/…
-
是的,但这并没有解决问题。它仍然会转到“错误”的位置
标签: javascript google-maps-api-3 geolocation ip-geolocation