I get a string from a servlet in my javascript which is actually an arraylist. I use gson to make the list into json and send response to js. I use var data = JSON.parse(xhr.responseText)
. The data
contains location coordinates.
data
contains something like this: ["12.1456","73.12453","12.786945","75.13451","12.4724,"78.12545"]
I store the latitudes in latArray
and longitudes in lngArray
like this:
for(i=0;i < data.length;i++)
{
if(i%2==0)
{
latArray = data[i];
console.log(data[i]);
}
else
{
lngArray = data[i];
}
}
Adding the values in the latArray
and lngArray
in marker code like this:
function initMap() {
var mapDiv = document.getElementById('map');
var map = new google.maps.Map(mapDiv, {
center: {lat: bla.blahh, lng: blaa.blaahh},
zoom: 15
});
for(i=0;i<data.length;i++)
{
var marker = new google.maps.Marker({
//position: {lat:latArray[i],lng:latArray[i+1]},
position: new google.maps.Marker(latArray[i],lngArray[i+1]),
map: map,
title:"This is the place."
});
}
}
But I get this error: js?callback=initMap:59 Uncaught TypeError: Cannot create property 'clickable' on string '1'
I dont know for sure if it's saying I have error in line 59. Here's what is in line 59 of the initMap()
var map = new google.maps.Map(mapDiv, {
center: {lat: bla.blahh, lng: blaa.blaahh},
zoom: 15
});