In this example, we will expand the Google Maps integration example from Chapter 4, Libraries, so that there will be a new option of showing the user where they are located on the Google Map. For doing so, we will use the HTML5 navigator.geolocation
service to request the browsing user to share its location with the application. If the user agrees, and is using an advanced browser, such as the latest Firefox, Chrome builds that support to this service. Once we get the values, we will collect the geolocation, and call a controller method to prepare the Google Map of that area to render a Google Map view with the option navigator
. We will use the HTML5 navigator.geolocation
service as follows:
navigator.geolocation.getCurrentPosition(getLocation, locationFail);
Here, getLocation
is called, if the location was successfully fetched, and locationFail
, if it was failed.
We will start with the controller first.