Modify the program as follows, this will look a bit simple to use v3
api standards.

directionsService.route(request, function(result, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    path = result.routes[0].overview_path;

    $(path).each(function(index, item) {
      polyline.getPath().push(item);
      bounds.extend(item);
    })

    polyline.setMap(map);
    map.fitBounds(bounds);
  }
});

http://marx-tseng.appspot.com/maps/Polyline_from_directions.html

On 7月14日, 下午11時52分, "[email protected]" <[email protected]>
wrote:
> On Jul 14, 7:36 am, Marx Tseng <[email protected]> wrote:
>
> > Try this.http://marx-tseng.appspot.com/maps/Polyline_from_directions.html
>
> These don't look like documented properties:
> polyline.getPath().push(new google.maps.LatLng(item.b, item.c));
>
> I would think this would break the next time the API changes.
> (but I could be wrong)
>
> This version uses documented API calls (not that those haven't changed
> with v3 also).http://www.geocodezip.com/V3_Polyline_from_directions.html
>
>   -- Larry
>
>
>
>
>
> > On 7月14日, 下午9時02分, Josh <[email protected]> wrote:
>
> > > I'm upgrading my code from v2 to v3 and I used to do something like
> > > the following in order to get a polyline of directions from two
> > > LatLngs:
>
> > >     newDirections.loadFromWaypoints([begin, end],{
> > >       getPolyline: true
> > >     });
>
> > >     google.maps.Event.addListener(newDirections, "load", function(){
> > >       var poly = newDirections.getPolyline();
>
> > > With v3 (where start/end are LatLngs)
>
> > > var directionsService = new google.maps.DirectionsService();
> > > var request = {
> > >   origin:      start,
> > >   destination: end,
> > >   travelMode:  google.maps.DirectionsTravelMode.DRIVING
>
> > > };
>
> > > directionsService.route(request, function(directionsResult,
> > > directionsStatus) {
> > >   if (directionsStatus == google.maps.DirectionsStatus.OK) {
>
> > >     path = directionsResult.routes[0].overview_path
>
> > >     console.log($.map(path, function(a){return [[a.lat(),
> > > a.lng()]]}) );
>
> > > And this is significantly less graceful, doesn't use the API and does
> > > silly mapping with jQuery AND I still don't have a polyline object.
>
> > > Is there a better way?
>
> > > Thanks!- Hide quoted text -
>
> > - Show quoted text -

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to