Hi Guys,
I’ve got a few locations that I’d like to put on a google map and can do it just fine when I use the following code:
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(52.583287, -0.237494), 13);
var point1 = new GLatLng(52.583287,-0.237494)
var point2 = new GLatLng(52.588345,-0.250711)
map.addOverlay(new GMarker(point1));
map.addOverlay(new GMarker(point2));
However, when I try to do it via an array the markers appear, but not in the correct location and I can’t figure out why.
Below is my version where I attempt to use an array:
var x;
var locations = new Array();
locations[0] = "52.583287,-0.237494";
locations[1] = "52.588345,-0.250711";
for (x in locations) {
var point = new GLatLng(locations[x]);
map.addOverlay(new GMarker(point));
}
I’m not quite sure which part is wrong, but if anyone can point it out, I’d really appreciate it.
I’ve tried that but it doesn’t work.
But you are correct that I cannot use strings, after a little research I found out that it must be a pair of float numbers.
In which case, my code should work fine when i remove the quotations, but it does not.
var x;
var locations = new Array();
locations[0] = [52.583287,-0.237494];
locations[1] = [52.588345,-0.250711];
for (x in locations) {
var point = new GLatLng(locations[x]);
map.addOverlay(new GMarker(point));
}
I’m not familiar with google maps but I think I spotted your error.
You are setting the coordinates as a string and depending on how strict google maps is with strings and numeric values, it may be causing your script not to work.
Original:
new GLatLng(52.583287, -0.237494)
Your script:
var point = new GLatLng(“52.583287,-0.237494”);
You can fix this by creating a bi-dimensional array. Each index holding the x and y values separately.
Example:
var locations = [];
locations[0] = [52.583287, -0.237494];