Hey Guys,
Corrected that but still having issuses. Current code is:
function addMap(coordinates) {
/*coordinates = coordinates.toString()
alert(coordinates);
*/
var coordinateString = "(18.66774725247165, -3.3367449040771535),
(54.6671516, -3.3574301),(54.6750929147338, -3.3477312322021535),
(54.6750929147338, -3.377256989038091),(54.667052323738794,
-3.393908142602544),(54.6671516, -3.3574301),(54.6671516,
-3.3574301),";
var coordinates = coordinateString.replace(/[(]/g, "");
coordinates = coordinates.replace(/[)],/g, "&");
var temp = [];
var temp2 = [];
//split marker string into individual markers
temp = coordinates.split("&");
//split first marker into lat and lng values
temp2 = temp[0].split(",");
alert(temp2[0] + " becomes " + parseFloat(temp2[0]));
alert(temp2[1] + " becomes " + parseFloat(temp2[1]));
var latlng = new google.maps.LatLng(parseFloat(temp2[0]),
parseFloat(temp2[1]));
alert(latlng);
map.setCenter(latlng);
marker = new google.maps.Marker({
position: latlng,
map: map
});
marker.setMap(map);
// -1 gets rid of the last string which is empty space
for (var i = 1; i < temp.length-1; i++)
{
temp2 = temp[i].split(",");
var latlng = new google.maps.LatLng(parseFloat(temp2[0]),
parseFloat(temp2[1]));
alert(latlng);
marker = new google.maps.Marker({
position: latlng,
map: map
});
marker.setMap(map);
}
}
I've but a few alerts in there so you can see what the values are when
testing it.
First issue: latlng appears to be fine, but i'm sure
map.setCenter(latlng); dosen't work. The code does not add any markers
to the map, and it also dosen't get to the alert inside the for loop.
Second issue: I want to pass through coordinates into this method,
which is exactly the same as coordinateString, but recieved from
MySql. When I comment out coordinateString and use coordinates which
has been passed through instead, then alert(coordinates) shows
'undefined', and it doesn't reach the next alert.
Third issue: Im still having the issue were every so often (3/4 times)
when I reload or update the page, the map doesn't load, only the grey
canvas, and I have to restart firefox to fix it. Any ideas?
Thanks guys,
Rick