2014-12-16 7 views
0

안녕하세요. phonegap에서 geolocation이 작동하지 않습니다. 여기 내 코드가있다.phonegap geolocation이 작동하지 않습니다.

function getGeo() { 
    alert("begin getGeo"); 
    navigator.geolocation.getCurrentPosition(onSuccess, onError); 
} 

function onSuccess(position) { 
    alert("onsuccess"); 
    var test = '"lat":"' + (position.coords.latitude) + '", "long":"' + (
     position.coords.longitude); 
    alert(test); 
} 

function onError(error) { 
    alert('code: ' + error.code + '\n' + 'messagee: ' + error.message + 
     '\n'); 
} 

"get getGeo"경고가 발생하며 아무런 반응이 없습니다.

내 config.xml 파일에이 행을 추가했습니다.

<gap:plugin name="org.apache.cordova.geolocation" version="0.3.10" /> 
+0

기기에서 설정 한 위치 서비스에서 처음 시도하면 다음 링크를 사용해보세요. http : //stackoverflow.com/questions/26037702/how-do-you-display-map-google-on-a-phonegap- android-application/26038477 # 26038477 – Ved

답변

0

이 시도 :

navigator.geolocation.getCurrentPosition(onSuccess, onError, {maximumAge:600000, timeout:5000, enableHighAccuracy: true}); 

function onSuccess(position) { 
    //Lat long will be fetched and stored in session variables 
    //These variables will be used while storing data in local database 
    localStorage.setItem("lat", position.coords.latitude); 
    localStorage.setItem("long", position.coords.longitude); 
} 
function onError(error) { 
    if (error.code == error.TIMEOUT) 
    { 
     // Attempt to get GPS loc timed out after 5 seconds, 
     // try low accuracy location 
     navigator.geolocation.getCurrentPosition(
       onSuccess, 
       errorCallback_lowAccuracy, 
       {maximumAge:600000, timeout:10000, enableHighAccuracy: false}); 
     return; 
    } 
    alert("GeoLocation didn't worked, try to reboot your internet connection or your device, the app will close now."); 
    navigator.app.exitApp(); 
} 

function errorCallback_lowAccuracy(error) { 
    alert("GeoLocation didn't worked, try to reboot your internet connection or your device, the app will close now."); 
    navigator.app.exitApp(); 
} 
+0

나는 그것을 테스트하고 함수 "errorCallback_lowAccuracy"에서 경고를 받았다. –

+0

기기를 재부팅하려고 시도한다. – Malakiof

+0

나는 그렇게한다. 그러나 여전히 같은 경고입니다. –

관련 문제