使用 html5 地理定位的网页不如 Google 地图准确?
Webpage using html5 geolocation not as accurate as Google Map?
在笔记本电脑上使用网络浏览器 Chrome,我打开了本地 html 网页以获取当前位置。 returned 位置 (1.3238272, 103.8606336) 离我的实际位置不远。相似度,像[1]这样的网站(1.3238272
103.8606336) [2] (1.32383, 103.86063) 所有 return 不准确的结果。
但是,使用 google map,它 returned (1.287264, 103.831497) 了一个非常准确的位置。 google 地图是否使用不同的 approach/technology 来获取位置?
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var g_lat = 0;
var g_lng = 0;
var map, infoWindow;
function initMap() {
navigator.geolocation.getCurrentPosition(updatePosition);
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: g_lat, lng: g_lng},
zoom: 8
});
infoWindow = new google.maps.InfoWindow;
}
function updatePosition(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
map.setCenter(pos);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
async defer></script>
</body>
</html>
错误是在用户登录时使用Google地图,这样会产生更好的定位结果。无需登录,结果位置与地理定位相同。
在笔记本电脑上使用网络浏览器 Chrome,我打开了本地 html 网页以获取当前位置。 returned 位置 (1.3238272, 103.8606336) 离我的实际位置不远。相似度,像[1]这样的网站(1.3238272 103.8606336) [2] (1.32383, 103.86063) 所有 return 不准确的结果。
但是,使用 google map,它 returned (1.287264, 103.831497) 了一个非常准确的位置。 google 地图是否使用不同的 approach/technology 来获取位置?
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var g_lat = 0;
var g_lng = 0;
var map, infoWindow;
function initMap() {
navigator.geolocation.getCurrentPosition(updatePosition);
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: g_lat, lng: g_lng},
zoom: 8
});
infoWindow = new google.maps.InfoWindow;
}
function updatePosition(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
map.setCenter(pos);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
async defer></script>
</body>
</html>
错误是在用户登录时使用Google地图,这样会产生更好的定位结果。无需登录,结果位置与地理定位相同。