-1
以下、私はHTML5ジオロケーションAPIを使用するコードを持っています。私が読んだすべての例では、常にボタンをクリックして場所を表示します。しかし、私はユーザーがページを読み込むとすぐにそれを表示したいと思います。私は以下の私のコードでそれを持っていたと思ったが、うまくいきません。 HTMLHTML5ジオロケーションAPIをページにロードする方法/ボタンをクリックしないで表示する方法?
var showLocation = document.getElementById("storeWeather");
function userLocation() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPoints);
} else {
showLocation.innerHTML = "Your browser does not support this feature.";
}
}
function showPoints (position) {
showLocation.innerHTML = "Latitude: " + position.coords.latitude +
"<br> Longitude: " + position.coords.longitude;
}