Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get Geolocation (Lattitude and Longitude) of a point in phonegap

    • 0
    • 3
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    If you want to track the location using phonegap App, you can simply checkout this steps.

    1. After creating a project for example "test", you can add a plugin using terminal

    cordova plugin add org.apache.cordova.geolocation
    

    After installing the plugin make sure your plugin is installed by using:

    cordova plugin ls
    

    It will show you something like this:

    [ 'org.apache.cordova.geolocation' ]
    


    After the confirmation of adding plugin, open your www folder and add the following lines in your code:
    HTML :

    <body>
        <div id="findLocation"></div>
      </body>
    

    JS :

        <script>
        document.addEventListener("deviceready", onDeviceReady, false);
    
            function onDeviceReady() {
                navigator.geolocation.getCurrentPosition(onSuccess, onError);
     // On device feady it will call this function
            }
            function onSuccess(position) {
                var div = document.getElementById('findLocation');
    
                div.innerHTML = 'Latitude: '             + position.coords.latitude         + '<br/>' +
                                'Longitude: '            + position.coords.longitude        + '<br/>' +
                                'Altitude: '             + position.coords.altitude         + '<br/>'';
            }
    
    
            function onError() {
                alert('onError!');
            }
        </script>
    

    It will give the Lattitude and Longitude of your location on device ready.
    You can also get your location on click of some button or on any event.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: