Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get current location in phonegap?

i added Geolocation plugin in my app and used this code for getting the current location in phonegap. but this code does not work.

    document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    alert("4");
    navigator.geolocation.getCurrentPosition(onSuccess, onError);
}

function onSuccess(position) {
    alert("1");
}

function onError(error) {
    alert("3");
}

Where is the problem in my code?

thank you and sorry for my poor english.

like image 404
Sadegh Bakhshandeh Sajjad Avatar asked Dec 01 '25 03:12

Sadegh Bakhshandeh Sajjad


1 Answers

  1. check if geolocation is properly installed or not

  2. restart your phone (silly solution but it works sometimes.I faced it once)

  3. check if your geo permissions & settings are turned on in device

  4. test with this code

    options = { enableHighAccuracy: true }; navigator.geolocation.getCurrentPosition(onSuccess, onError, options);

  5. If you're using android, try to get the error with eclipse logcat.

like image 107
AtanuCSE Avatar answered Dec 06 '25 11:12

AtanuCSE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!