English 中文(简体)
• 如何从山洞地图的方向展示多条线?
原标题:how to display multiple polylines from directions in google maps?

i want to draw multiple polylines on the google map, for multiple routes. for this i am using google.maps.DirectionsService

function drawPolyline(source,destination,waypoints){
        // show route between the points
        directionsService = new google.maps.DirectionsService();
        directionsDisplay = new google.maps.DirectionsRenderer(
        {
            suppressMarkers: true,
            suppressInfoWindows: true
        });
        directionsDisplay.setMap(map);
        var request = {
            origin:source, 
            destination:destination,
            waypoints:waypoints,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, function(response, status) 
        {
            if (status == google.maps.DirectionsStatus.OK) 
            {
                directionsDisplay.setDirections(response);

            }
        });

      }

but when i call this method multiple times, only last polyline is appearing. and i want different colors for different polylines.

最佳回答

Directions lets you inspect the route: http://code.google.com/apis/maps/documentation/javascript/directions.html#InspectingResults

The DirectionsResult object has and array of routes[], which allows you to get a set of encoded polylines that makes up the route:

if (status == google.maps.DirectionsStatus.OK) 
            {
                directionsDisplay.setDirections(response);
                myRoutes[]=response.routes[];

            }

如Scottux所述,你可以使用这些路线修建多线透支。

问题回答

你们需要使用一条多线,而不是一条方向。

var line = new google.maps.Polyline({clickable:true,map:map,path:"some lat,lngs"});

Please look at the api here: http://code.google.com/apis/maps/documentation/javascript/reference.html#Polyline Options are listed here: http://code.google.com/apis/maps/documentation/javascript/reference.html#PolylineOptions

指导员在提纲上很灵活,只是简单方向功能的助手。

您实际上可以直观多个<代码>Directions Renderer,将其全部放在同一个地图上,并将在同一个地图上公布。

enter image description here





相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签