私はJavaスクリプトを初めて使用するので、すぐにサポートが必要です。これが私のコードです:
<html>
<head>
<title> GeoLocation Application </title>
<script>
$counter=0;
while ($counter < 10) {
if (!navigator.geolocation) {
alert('Your browser does not support geolocation');
} else {
navigator.geolocation.getCurrentPosition(success, error);
document.write("Count ",$counter,"<br>");
}
$counter ++;
}
function success(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
alert (lat +','+lng);
document.write("calling update mysql");
//document.location='update_java_data.php?lat=' + lat+'&lng='+lng;
}
function error(error) {
alert('an erro occured, error code is '+error);
}
</script>
</head>
<body>
<h1> Hello </h1>
</body>
</html>
ナビゲーターを使って10回座標を取得しようとしています。しかし、0から9までのカウンター表示のクイックリストだけが表示されている場合、「 "calling update mysql"」と表示されるのは一度だけです。私にとっては、成功関数を1回だけ実行したことを意味します。
座標を10回取得する方法はありますか(つまり、成功関数を10回呼び出す必要があると思います)。