初めてnavigator.geolocation.getCurrentPosition(success, error, options);
を実行すると、ユーザーの所在地を取得できます。私はこの仕事を得ることができますどのように、私は成功しませんthis question's answersで与えられたアドバイスに従っているnavigator.geolocationが2回目の実行でエラーを返す - IE
The current position could not be determined.
:しかし、上の第二の実行から、関数はエラーを返しますか?
ここにはworking fiddleがあり、エラーをすばやく確認できます。
//Pass this options to the getCurrentPosition
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
//function to execute if the current position was succesfully retrieved
function success(pos) {
console.log(pos);
var crd = {lat: pos.coords.latitude, lng : pos.coords.longitude };
var myPre = document.querySelector('pre');
myPre.textContent = JSON.stringify(crd);
myPre.style.color = someColor(); // use a diferent color just to see it's a new execution of the code
};
//execute this on error
function error(err) {
var myPre = document.querySelector('pre');
myPre.textContent = err;
myPre.style.color = someColor(); // use a diferent color
};
//attach function to button
var myButton = document.querySelector('button');
myButton.addEventListener('click', function(){
navigator.geolocation.getCurrentPosition(success, error, options);
});
は、私は意図的にコードスニペットを追加していなかったので、それが反映されていない版をロールバックこのエラーは有用ではありません。したがって、エラーが見られ、テストされることができるフィドル。 – randomguy04