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

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!

-- 
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