The Geolocation API is a separate specification and is part of the HTML5 stack. You can use JavaScript and locate the client device location using various techniques, such as IP address, Wi-Fi, GSM/CDMA cell IDs, or device Global Positioning System (GPS). This recipe shows you how to find the current location using the Geolocation API in your app.
Copy the full code of this recipe from the code/11/geolocation
folder. You can launch this code using the URL: http://localhost:8080/11/geolocation/main.html
.
The steps to be followed are:
Create
main.html
with an emptydiv
tag to display the geolocation information.<div data-role='content'> <p>You current Position is ...</p> <div id='geopos'></div> </div>
Invoke the
getCurrentPosition()
method to obtain the current location using ashow_pos()
callback function.$('#main').live('pageinit', function(event) { if (navigator.geolocation...