1
Heey People,HTML5 지구 위치 iphone
내 아이폰의 GPS 위치를 찾기 위해 뭔가를 작성했습니다. 내 위치가 발견되면 내 위치가 경고 상자에 표시됩니다.
하지만 분명히 내 아이폰에 경고 상자를 계속해서 보여줍니다.
콜백 함수를 설정할 수 있도록 클래스를 작성했습니다. 위치를 얻으려고 할 때 위치를 찾을 때까지 설정되지 않기 때문입니다.
위치를 찾으면 콜백 기능이 실행됩니다.
내가 찾은 후 위치 추적기를 중지하는 방법을 누구에게도 알려 줄 수 있습니까?
내 클래스 :
GPS = function() {
this.constructor();
}
var gpsLatitude = 0.0, gpsLongitude = 0.0, gpsCallback;
GPS.prototype.constructor = function(){
this.getLocation();
}
var afterNotification = function(){
//Do something
};
GPS.prototype.setCallback = function(myfunction){
gpsCallback = myfunction;
}
GPS.prototype.getLocation = function(){
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(this.showPosition, this.showError);
}
else{
Lungo.Notification.error(
"Error", //Title
"Your device doesnt support GPS", //Description
"cancel", //Icon
7, //Time on screen
afterNotification //Callback function
);
}
}
GPS.prototype.showPosition = function(position)
{
gpsLatitude = position.coords.latitude;
gpsLongitude = position.coords.longitude;
gpsCallback();
}
GPS.prototype.getLatitude = function()
{
return gpsLatitude;
}
GPS.prototype.getLongitude = function()
{
return gpsLongitude;
}
GPS.prototype.showError = function(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
Lungo.Notification.error(
"Error", //Title
"Gebruiker staat geolocatie niet toe", //Description
"cancel", //Icon
7, //Time on screen
afterNotification //Callback function
);
break;
case error.POSITION_UNAVAILABLE:
Lungo.Notification.error(
"Error", //Title
"Locatie niet beschikbaar", //Description
"cancel", //Icon
7, //Time on screen
afterNotification //Callback function
);
break;
case error.TIMEOUT:
Lungo.Notification.error(
"Error", //Title
"Locatie timeout", //Description
"cancel", //Icon
7, //Time on screen
afterNotification //Callback function
);
break;
case error.UNKNOWN_ERROR:
Lungo.Notification.error(
"Error", //Title
"Unkown location error", //Description
"cancel", //Icon
7, //Time on screen
afterNotification //Callback function
);
break;
}
}
var GPS = new GPS();
I 클래스 사용 방법 :
var callback = function()
{
alert(GPS.getLongitude() + ", " + GPS.getLatitude());
}
GPS.setCallback(callback);
첫 번째 위치를 얻은 후에 navigator.geolocation.clearWatch()를 시도해보십시오. – Ares
팁을위한 Thx,하지만 제대로 작동하지 않는 이유는 내가 getLattitude 함수에서 실수를했기 때문입니다. 다시 거기에 요청했습니다. –