PDA

View Full Version : Resolved For loop run once



bluewalrus
12-09-2010, 05:49 PM
I've got this code which creates a google map. The map part is fine currently but the syntax of the for I think is off because it is only processing once. Does anyone see something wrong with it? Thanks.


for (var i = 0; i < 5; i++) {
var location = new google.maps.LatLng(lat[i], lng[i]);
var marker = new google.maps.Marker({
position: location,
map: map
});
var bounds = new google.maps.LatLngBounds(lat[i], lng[i]);
map.fitBounds(bounds);
map.fitBounds(bounds);
map.setCenter(location);
alert(i);
}

Here's a link as well:

http://174.120.151.156/~crazychr/test2.html

Schmoopy
12-09-2010, 05:59 PM
The problem's not with the for loop itself, I'm getting a JavaScript error when I run that page:




Error: a.lat is not a function
Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/3/3a/main.js
Line: 12


So it just stops working after that, try and play around with it, see what line is generating that error and see what you need to do to change it.

bluewalrus
12-09-2010, 06:23 PM
Yup you were correct. Thanks.

I anyone stumbles across this I got my solution here:

http://stackoverflow.com/questions/1556921/google-map-api-v3--set-bounds-and-center