Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I assume you have referred <a href="http://docs.phonegap.com/en/2.8.0/index.html" rel="nofollow">Phonegap's Getting Started Guide</a> to create basic project.</p> <p>This is the script to get Lattitude and Longitude</p> <pre><code>/* * This file contains script to get lattitude and longitude * */ var lat = 0; var lng = 0; //A button click will call this function function getLocation() { navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true }); } // onSuccess Geolocation // function onSuccess(position) { //Lat long will be fetched and stored in session variables //These variables will be used while storing data in local database lat = position.coords.latitude; lng = position.coords.longitude; alert('Lattitude: ' + lat + ' Longitude: ' + long); sessionStorage.setItem('lattitude', lat); sessionStorage.setItem('longitude', lng); } // onError Callback receives a PositionError object // function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } </code></pre> <p>You will have to add necessary permissions in your <strong>manifest</strong> file.</p> <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /&gt; </code></pre> <p>Call <code>getLocation()</code> function onclick event of button or wherever you wish to get geolocation.</p> <p>For more details refer <a href="http://docs.phonegap.com/en/2.8.0/cordova_geolocation_geolocation.md.html#Geolocation" rel="nofollow">Phonegap Geolocation Documentation</a></p> <p>To show google map please refer <a href="https://developers.google.com/maps/documentation/javascript/reference#Map" rel="nofollow">Google MAP API</a></p> <p>Hope that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload