Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 04:18 AM   PM User | #1
hiyatran
New Coder

 
Join Date: Jun 2010
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
hiyatran is an unknown quantity at this point
Loop in an Array??

I would like to put all my coordinates into an array and have a loop display each one but with a Google function.


Here's the code, which draws the points on google map:

Code:
 var flightPlanCoordinates = [
    new google.maps.LatLng(37.772323, -122.214897),
    new google.maps.LatLng(21.291982, -157.821856),
    new google.maps.LatLng(-18.142599, 178.431),
    new google.maps.LatLng(-27.46758, 153.027892)
  ];
I would like to be able to do something like this:

Code:
var arrPos = new Array([37.772323, -122.214897], [21.291982, -157.821856], [-18.142599, 178.431], etc. );

var flightPlanCoordinates = [ + 
   for (i=0; i<arrPos.length; i++){
      new google.maps.LatLng(arrPos[0]) + ", "
   }
   + "];"

I know you can put a loop in an array but is there an alternate method to retrieving the points from the array??

tks
__________________
Daily Hot Deal
hiyatran is offline   Reply With Quote
Old 10-11-2012, 07:01 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Code:
var arrPos = new Array([37.772323, -122.214897], [21.291982, -157.821856], [-18.142599, 178.431], etc. );
var flightPlanCoordinates = [];

for(i=0; i<arrPos.length; i++) {
   flightPlanCoordinates.push(new google.maps.LatLng(arrPos[i][0], arrPos[i][1]));
}
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:50 AM.


Advertisement
Log in to turn off these ads.