html5 geolcation apiを介してユーザーのジオロケーションを取得しようとしていますが、次のスニペットを使用しています。
if (navigator.geolocation) {
var timeoutVal = 10 * 1000 * 1000;
navigator.geolocation.getCurrentPosition(
displayPosition,
displayError,
{ enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0 }
);
}
else {
// DO SOME STUFF HERE
}
function displayPosition(position) {
// configuration
var myZoom = 12;
var myMarkerIsDraggable = true;
var myCoordsLenght = 6;
var defaultLat = position.coords.latitude;
var defaultLng = position.coords.longitude;
document.getElementById('latitude').value = defaultLat;
document.getElementById('longitude').value = defaultLng;
/*
1. creates the map
2. zooms
3. centers the map
4. sets the map’s type
*/
var map = new google.maps.Map(document.getElementById('canvas'), {
zoom: myZoom,
center: new google.maps.LatLng(defaultLat, defaultLng),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
});
// centers the map on markers coords
map.setCenter(myMarker.position);
// adds the marker on the map
myMarker.setMap(map);
}
function displayError(error) {
var errors = {
1: 'Permission denied',
2: 'Position unavailable',
3: 'Request timeout'
};
alert("Error: " + errors[error.code]);
}
});
上記のアプローチの問題点は、使用が難しいと感じているユーザーがほとんどいないことです。まれに、 [許可]ではなく[拒否]をクリックして、画面を見つめ続けています。したがって、ユーザビリティの観点から、良いアプローチは次のようになると思います。
彼らに許可を求めてください。
3秒間待ちます。[拒否]をクリックするか、応答しない場合は、IPを使用して地図上に地理を表示します。
上記のスニペットの2番目のステップを実行するにはどうすればよいですか。教えてください、ありがとう!ただし、処理するためのより良い方法は何でしょうか