2

I'm upgrading an old hybrid application.
Now I have the latest versions of jQuery (1.7 -> 2.2.4) and jQuery Mobile (1.1 -> 1.4.5), and I use too Jquery Migrate (1.4.1).
This app contains a page with a map created with jquery-ui-map and I'm testing the app with PhoneGap.
In this page, I have a button and I would like to get current position of user.
I use this code:

    $('#button-getcurrentposition').click(function(){

        $('#map-canvas').gmap('getCurrentPosition', function(position, status) {

            alert("I'm here");

            if ( status === 'OK' ) {
                var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                $('#map-canvas').gmap('option','center', clientPosition);   
            }
        });         

    });

but the alert "I'm here" never displays and I don't know why, so I can not have the current position of the user.
I have included jquery.ui.map.extensions.js, jquery.ui.map.overlays.js and jquery.ui.map.services.js.
I have the same problem with the web app version and the apk or ipa.
Is there someone with the same problem? Does anyone know why the alert "I'm here" doesn't display? Is the function "getCurrentPosition" deprecated with the latest version of jquery or cordova?
Thank you so much

Giu
  • 295
  • 1
  • 5
  • 22

1 Answers1

0
    $('#button-getcurrentposition').click(function(){

        $('#map-canvas').gmap('getCurrentPosition', function(status, position) {

            alert("I'm here");

            if ( status === 'OK' ) {
                var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                $('#map-canvas').gmap('option','center', clientPosition);   
            }
        }, { timeout: 4000, enableHighAccuracy: true });        

    });

I believe these after parts are required and you have the variables in the function the wrong way around according to the docs.

Deckerz
  • 2,606
  • 14
  • 33
  • OMG! Works! Thank you so much! But now I have another problem. The status is "object positionError". Do you know something about this error? Thanks – Giu Aug 17 '17 at 15:25
  • @Giu what line is that error? in the code context above – Deckerz Aug 17 '17 at 15:26
  • The variable "status" contains "object positionError". If I print alert(status); returns "positionError". Code: if ( status === 'OK' ) – Giu Aug 17 '17 at 15:28
  • status becomes a positionError object if the location cannot be retrieved. You need to check if status is not a instance of a class first before `status === 'OK'` – Deckerz Aug 17 '17 at 15:31
  • mmmh, it's quite ok... i'm not sure to understand what do you mean with "check if status is not a instance of a class"... but why the location cannot be retrieved? What are the reasons? Is it a problem of code or I need to include something permission in android manifest? – Giu Aug 17 '17 at 15:54