We can use Cordova's org.apache.cordova.geolocation
plugin to access the hardware's geolocation services.
Begin by installing the geolocation plugin using the following command:
cordova plugin add org.apache.cordova.geolocation
Once installed, we can use Cordova's navigator.geolocation
object to access the hardware's geolocation services.
To access the device's geolocation information, we use the getCurrentPosition()
method:
Add the following HTML to
index.html
:<div data-role="view" id="app-location" data-title="Location" data-layout="layout"> <h3>Location</h3> <p> <a data-role="button" data-click="app.demos.location.onFetchLocation"> Fetch Location</a> </p> <p id="location-status" style="display: none;"> <i>Fetching position...</i> </p> <p id="location-error" style="display: none;"></p> <ul id="location-info" data-role="listview...