The third feature is to about rendering the map in the view. To implement this feature, we will:
Let's start by creating a method to retrieve the user location form the browser. The current user location information will be used to initialize the map. We will use the getCurrentPosition
method of the Geolocation
class provided by the browser to get the user's current location.
Tip
The Geolocation
class provides methods to obtain the location of the device. The location information can be used to provide a customized experience to the user. The API reference for Geolocation
class can be found at https://developer.mozilla.org/en-US/docs/Web/API/Geolocation.
Define an attribute to hold the user's current location, call it localLocation
. Initialize this attribute with your local longitude and latitude:
var localLocation = {lat: -37.810432, lng: 144.96616};
The initial...