best way to handle route with more than 8 points

2,671 views
Skip to first unread message

WebEngineer

unread,
Jul 10, 2011, 7:15:58 AM7/10/11
to google-map...@googlegroups.com
My map at www.Violette.com tracks our travels in our motorhome. What is the best way to display the route we have taken since it has more than 8 stops?

geoco...@gmail.com

unread,
Jul 10, 2011, 10:14:44 AM7/10/11
to Google Maps JavaScript API v3
On Jul 10, 7:15 am, WebEngineer <davidaviole...@gmail.com> wrote:
> My map atwww.Violette.comtracks our travels in our motorhome. What is the
> best way to display the route we have taken since it has more than 8 stops?

Your only option is to create multiple routes each with less than 10
stops (start, end and 8 waypoints).

I would probably capture the polyline from the previous stops and save
it for display, you probably don't need all of the "directions" for
the places you have been and if you want them you could just query for
that piece of the route.

You probably want to verify that you believe the above is acceptable
per the terms of use.

-- Larry

David Violette

unread,
Jul 10, 2011, 1:09:17 PM7/10/11
to google-map...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Thanks, Larry.
How to capture the polyline? You're correct in that I don't care about directions, just to display the path.
Would I display the polyline(s) using KML?


--
- - - - - - - - - - - - - - - - - - -
David A. Violette
DavidAV...@gmail.com
Da...@Violette.com
Da...@SitePower.com

geoco...@gmail.com

unread,
Jul 10, 2011, 2:19:33 PM7/10/11
to Google Maps JavaScript API v3
On Jul 10, 10:09 am, David Violette <davidaviole...@gmail.com> wrote:
> On Sun, Jul 10, 2011 at 10:14 AM, geocode...@gmail.com <geocode...@gmail.com
>
> > wrote:
> > On Jul 10, 7:15 am, WebEngineer <davidaviole...@gmail.com> wrote:
> > > My map atwww.Violette.comtracksour travels in our motorhome. What is the
> > > best way to display the route we have taken since it has more than 8
> > stops?
>
> > Your only option is to create multiple routes each with less than 10
> > stops (start, end and 8 waypoints).
>
> > I would probably capture the polyline from the previous stops and save
> > it for display, you probably don't need all of the "directions" for
> > the places you have been and if you want them you could just query for
> > that piece of the route.
>
> > You probably want to verify that you believe the above is acceptable
> > per the terms of use.
>
> >  -- Larry
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
> Thanks, Larry.
> How to capture the polyline?

I have an example here that saves it as xml:
http://www.geocodezip.com/v3_GoogleEx_directions-draggable2Xml.html

It creates the xml that most of my pages process, but it shouldn't be
too hard to change.

> You're correct in that I don't care about directions, just to display the path.
> Would I display the polyline(s) using KML?

That would probably be more efficient (KmlLayer would create tiles
from your kml), you would just need to modify the output to be kml.
FusionTables would be another option (but you would be importing kml
into there also), it might give you options further down the road.

-- Larry

>
> --
> - - - - - - - - - - - - - - - - - - -
> David A. Violette
> DavidAViole...@gmail.com
> Da...@Violette.com
> D...@SitePower.com- Hide quoted text -
>
> - Show quoted text -

Roger Hampson

unread,
Aug 9, 2011, 5:23:49 PM8/9/11
to google-map...@googlegroups.com
Your only option is to create multiple routes each with less than 10
stops (start, end and 8 waypoints).
How would I do that? I tried duplicating the code that creates a route, but the first route disappeared when the second route was displayed.

MymsMan

unread,
Aug 10, 2011, 3:42:44 AM8/10/11
to google-map...@googlegroups.com
You would need to create an arrray of direction renderer objects so that when creating the second route you dont overlay the first,

Roger Hampson

unread,
Aug 10, 2011, 4:52:36 AM8/10/11
to google-map...@googlegroups.com
I'm sorry but I am not very good at Javascript. This is the code I am trying in order to create the two routes I want

function calcRoute() {
     var request = [{
         origin: startlatlng,
         destination: joinLatLng,
         waypoints: [{ location: day1 }, { location: day2 }, { location: day3 }, { location: joinLatLng}],
         travelMode: google.maps.DirectionsTravelMode.DRIVING
     },
     {
         origin: joinLatLng,
         destination: endlatlng,
         avoidHighways: true,
         waypoints: [{ location: joinLatLng }, { location: day7 }, { location: day8 }, { location: day9 }, { location: day10 }, { location: day11 },
             { location: day12 }, { location: day13}],
         travelMode: google.maps.DirectionsTravelMode.DRIVING
     }];
 
    directionsService.route(request, function (response, status) {
         if (status == google.maps.DirectionsStatus.OK) {
             directionsDisplay.setDirections(response);
         }
 
    });
 
}
 
As you can see, I have tried to make request an array. I don't think that was what you meant though because it doesn't work. Can you please provide a bit more help.

David Violette

unread,
Aug 10, 2011, 7:53:07 AM8/10/11
to google-map...@googlegroups.com
Check the code at my site Violette.com for one way of doing this. I handle each route segment as a separate entity and all remain in view. I'm no expert, though, so there may be a better way to do this.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

--
- - - - - - - - - - - - - - - - - - -
David A. Violette
DavidAV...@gmail.com
Da...@Violette.com
Da...@SitePower.com

Roger Hampson

unread,
Aug 12, 2011, 4:48:54 AM8/12/11
to google-map...@googlegroups.com
I have looked at your site but I do not see a direction line drawn between the markers. Should there be one?

Roger Hampson

unread,
Aug 12, 2011, 4:56:40 AM8/12/11
to google-map...@googlegroups.com
I thought I might catch the response from

directionsService.route(request1,

function (response, status) {

if (status == google.maps.DirectionsStatus.OK) {

fullRoute = response;

}

});

and concat the response from the second directionsService.route to it, and then call

directionsDisplay.setDirections(fullRoute);

 

but it doesn't work either, I think, because of my knowledge of javascript and Google Maps.

David Violette

unread,
Aug 12, 2011, 5:50:18 AM8/12/11
to google-map...@googlegroups.com
Yes, I always see the route path line(s) drawn. A violet one for actual and a thinner black one for planned. The actual line should start at marker 0 in Phoenix AZ and should end (currently) at marker 23 in Pointe a la Croix, QC. I wonder why you don't get the lines.. Browser? Speed? Don't know.

On Fri, Aug 12, 2011 at 5:48 AM, Roger Hampson <roger....@talktalk.net> wrote:
I have looked at your site but I do not see a direction line drawn between the markers. Should there be one?

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

David Violette

unread,
Aug 12, 2011, 5:51:26 AM8/12/11
to google-map...@googlegroups.com
I guess we'll have to see if one of the experts weighs in on concatenation, since it is beyond my knowledge...

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Roger Hampson

unread,
Aug 13, 2011, 5:04:37 AM8/13/11
to google-map...@googlegroups.com
I have solved this as follows after advice from Danny Cohn in the Stack Overflow forum.
 
directionsDisplay is a DirectionsRenderer object. It can only render one set of directions at once. If you create 2 directions renderer objects, such as directionsDisplay1 and directionsDisplay2, each can render one half of the route on the map at the same time.
 
So I created one directionsDisplay to render the map and the first route and another to render the other route. I rendered both and defined their map in function init(). I then calculated and displayed each route. Job done!!

David Violette

unread,
Aug 13, 2011, 5:50:16 AM8/13/11
to google-map...@googlegroups.com
Yes, that is the only way I have been able to find to do it. In my solution I create separate .js files with each set of points from codebehind and then do a path for each successive set. While it gets the job done, it is not a good solution in my mind because each time I get beyond the 8 points for a set I have to manually add programming to generate the next set of points and manually add programming to process the added point set for directions. Since my history points do not change and we take about two months or more to add 8 points to the path this is not an onerous burden.

I have thought about saving path segments as KML polylines and displaying them that way instead of using DirectionsRenderer each time. The KML polylines would be used for the previous sets of 8 and DirectionsRenderer for the current set of up to 8. But I haven't had the time to do the programming for that and I am not sure it really reduces the need for the manual steps.

Thanks for your update on the topic, Roger! I'll update it as well if/when I find something different.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Roger Hampson

unread,
Aug 14, 2011, 11:52:24 AM8/14/11
to google-map...@googlegroups.com
Sorry I wasn't able to discern that technique from your code, David, but, not being an expert in Javascript, I couldn't see the wood for the trees.
 
As you say, whatever method you use, it means that you will have to change something that creates the webpage. I'm tracking a colleague that is cycling 1000 miles from Land's End to John O'Groats, the full length of the UK. I am going to have to go in every night to create a marker showing his latest position. He's 77 by the way and intends to do it in 14 days!!

David Violette

unread,
Aug 14, 2011, 5:12:16 PM8/14/11
to google-map...@googlegroups.com
Well, I am 72 but my traveling is by motorhome! And the mapping documents our stops in the past and planned stops in the near future.

All my stops are stored in an Access database as is my schedule. Any time my schedule is changed the marker files are updated. Those are the files TripMarkers1.js, TripMarkers2.js, etc, and TripMarkersPlan.js. Then my page code reads and processed those files to display the markers and to generate the routes. You could use my code if you wanted to but update the marker files manually.

If you want, I would be happy to add more annotation so it would be easier to follow.

On Sun, Aug 14, 2011 at 12:52 PM, Roger Hampson <roger....@talktalk.net> wrote:
Sorry I wasn't able to discern that technique from your code, David, but, not being an expert in Javascript, I couldn't see the wood for the trees.
 
As you say, whatever method you use, it means that you will have to change something that creates the webpage. I'm tracking a colleague that is cycling 1000 miles from Land's End to John O'Groats, the full length of the UK. I am going to have to go in every night to create a marker showing his latest position. He's 77 by the way and intends to do it in 14 days!!

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Roger Hampson

unread,
Aug 15, 2011, 3:18:13 AM8/15/11
to google-map...@googlegroups.com
Thanks for the offer, but at the moment this is a one-off exercise. Once the trip has finished, the page will be removed. If you want to have a look, the site is www.royalleamingtonspabc.org.uk. The new page will be up in the next few days.
 
Roger Hampson
Reply all
Reply to author
Forward
0 new messages