After retrieving the lat and lng positions from the database, I attempted to replace them in the center JSON object, but encountered an issue. The console displayed the position as
{lat:31.752809648231494,lng:-7.927621380715323}
, which then led me to convert it to JSON format.
{lat: 31.752809648231494, lng: -7.927621380715323}
I suspected that the presence of double quotes in the JSON data might be causing the problem. To resolve this, I tried removing the double quotes using the following code:
var pos = position.replace(/\"/g, "");
console.log(pos);//{lat:31.752809648231494,lng:-7.927621380715323}
var json = JSON.parse(position);
console.log(json); //{lat: "31.752809648231494", lng: "-7.927621380715323"}
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 31.791702, lng: -7.092620000000011},
zoom: 6,
mapTypeId: 'roadmap'
});