Search code examples
javascriptandroidjquerycordovajquery-ui-map

Get current position with jquery ui map (gmap)


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


Solution

  •     $('#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.