We can use various resources to get the user's position, so we are using the HTML5 API in this example. We will use an external JavaScript file to create a map with the exact location of the user:
Create a file called
getCurrentPosition.js
and save it within thepublic/js
folder.Place the following code in
getCurrentPosition.js
:function getCurrentPosition() { // Check boreswer/navigator support if (navigator.geolocation) { var options = { enableHighAccuracy : true, timeout : Infinity, maximumAge : 0 }; navigator.geolocation.watchPosition(getUserPosition, trackError, options); } else { alert('Ops; Geolocation is not supported'); } // Get user position and place a icon on map function getUserPosition(position) { // Check longitude and latitude console.log(position.coords.latitude); console.log(position.coords...