I am currently working on a project where I need to dynamically fetch longitude and latitude values from the browser geolocation and then include them in the options array for the Google Maps API. Here is the code snippet I am using:
function initMap(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(position =>{
long = position.coords.longitude;
lat = position.coords.latitude;
var options = {
zoom: 12,
center: {lat: ${lat},${long}}
}
var map = new google.maps.Map(document.getElementById('map'), options);
});
}
Unfortunately, I am facing an issue where the variables I have set up for the latitude and longitude values are not being accepted by the options > center tag. I have tried different approaches but no luck so far. Can someone guide me on how to solve this problem or if there is something I might be overlooking?
Appreciate any help!