好的,所以我使用Google Maps API作为我的网站,并使用“设置当前位置”功能。Google Maps API v3 - “设置当前位置”的最准确方法
它对一些用户来说很好,但对于其他用户来说,这是默认的“错误”位置。
例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尝试回答?: http://stackoverflow.com/questions/2851089/using-google-maps-api-how-can-we-set-the-current-location- as-the-default-set-lo – 2012-10-22 20:15:23
是的,但那并没有解决问题。它仍然去'错误的地点 – tristanojbacon