ノートパソコンでウェブブラウザのChromeを使用して、ローカルのhtmlウェブページを開いて現在地を取得しました。返された場所(1.3238272、103.8606336)は、私の実際の場所に近い場所ではありません。同様に、[1](1.3238272 103.8606336)[2](1.32383、103.86063 )のようなWebサイトはすべて、正確ではない結果を返します。
ただし、グーグルマップを使用すると、(1.287264、103.831497)非常に正確な場所が返されました。グーグルマップは場所を取得するために異なるアプローチ/テクノロジーを使用していますか?
<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マップを使用することです。これにより、より良い位置情報が得られます。ログインしない場合、結果の場所はジオロケーションと同じになります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加