Results 1 to 3 of 3

Thread: For loop run once

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default For loop run once

    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.

    Code:
    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
    Last edited by bluewalrus; 12-09-2010 at 06:23 PM.
    Corrections to my coding/thoughts welcome.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    The problem's not with the for loop itself, I'm getting a JavaScript error when I run that page:


    Code:
    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.

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    bluewalrus (12-09-2010)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yup you were correct. Thanks.

    I anyone stumbles across this I got my solution here:

    http://stackoverflow.com/questions/1...nds-and-center
    Corrections to my coding/thoughts welcome.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •