polyline loop

131 views
Skip to first unread message

fireofhellx

unread,
Apr 23, 2011, 7:52:05 AM4/23/11
to google-map...@googlegroups.com
ok so the issues im having it trying to get an array of latlng's to plot as polly lines 
there are about 72 lines in this array i need to plot but im having issues i know it needs to loop somewhere but unsure where im still new to google maps and javascript so any help would be amazing 

so here is the section im having issues with

// polylines
var one;
//pull out the line id's from top array
for (one in top)
{
//document.write("one = " + one + "<br />");
//get the mid arrays
two = top[one];
//document.write("two = " + two + "<br />");
for (var a = 0; a < two.length; a++)
{
//get the lat & lon from the mid array
var cords = two[a];
//document.write("cords = " + cords+ "<br />");
var allpaths = [new google.maps.LatLng(cords)];
var point = new google.maps.Polyline({
path:allpaths,
strokeColor: "#FF0000",
     strokeOpacity: 1.0,
     strokeWeight: 2
});
point.setMap(map);
}
}


here is a link to where it is live if that helps
its line 277 -338
please note that this is for a uni project and im learning as i go

geoco...@gmail.com

unread,
Apr 23, 2011, 11:01:50 AM4/23/11
to Google Maps JavaScript API v3
Your map doesn't work for me. It doesn't initialize if I deny
geolocation.

-- Larry

fireofhellx

unread,
Apr 23, 2011, 11:10:18 AM4/23/11
to google-map...@googlegroups.com
oh sorry forgot to mention this going to be for mobile ill just sort that now

fireofhellx

unread,
Apr 23, 2011, 11:23:29 AM4/23/11
to google-map...@googlegroups.com
ok ive hard coded the location. i have build the whole thing around the users location so you need to except the geolocation however it will centre the map in the location the polylines should appear hope that helps you help me

geoco...@gmail.com

unread,
Apr 23, 2011, 11:24:53 AM4/23/11
to Google Maps JavaScript API v3
On Apr 23, 8:10 am, fireofhellx <homem...@aol.com> wrote:
> oh sorry forgot to mention this going to be for mobile ill just sort
> that now

Using document.write for debugging is bad. It overwrites the page.

-- Larry

fireofhellx

unread,
Apr 23, 2011, 11:28:51 AM4/23/11
to google-map...@googlegroups.com
i know but ive had to use a lot of loops to get information out of a massive xml file and ive found document.write is useful to debug within loops. i think i have comment out all of them now sorry for the inconvenience 




Danny

geoco...@gmail.com

unread,
Apr 23, 2011, 11:52:01 AM4/23/11
to Google Maps JavaScript API v3
Suggestion for you.

1. Simplify your code to just display the polylines from the xml.
2. fix any javascript errors
3. post a link to the simplified page if still doesn't work.

-- Larry


>
> Danny

fireofhellx

unread,
Apr 23, 2011, 12:06:43 PM4/23/11
to google-map...@googlegroups.com
i am still new to google maps and javascript, however all of my code is just to get the information from my xml and display the polyline, from what i can see my issues is that im passing a var called "cords"(on line 295) which contains a lat and lng value in this format (lat,lng) so when i do "allpaths = [new google.maps.LatLng(cords)];" on line 308 it dose not seem to understand that cords has both the lat and lng values so. as far as i can see i 

1. need to somehow split "cords" into to variables or
2. find a way for  "[new google.maps.LatLng()]; " to understand that both the lat and lng are within that single variables.

i know my code is very messy and not clearly labelled and i am very grateful for your help and time

Rossko

unread,
Apr 23, 2011, 3:05:44 PM4/23/11
to Google Maps JavaScript API v3
> 1. need to somehow split "cords" into to variables or

http://www.google.com/search?q=split+a+javascript+string+at+a+comma

You'd probably also want to convert your string fragments to numbers
http://www.google.com/search?q=javascript+parsefloat

> 2. find a way for  "[new google.maps.LatLng()]; " to understand that both
> the lat and lng are within that single variables.

It won't, it demands two numbers.
Reply all
Reply to author
Forward
0 new messages