2016-11-29 1 views
-1

Ich verwende google directions, um die Hauptroute zwischen zwei Punkten und ihre Alternativen zu erhalten (3), so dass jede Alternative Schritte und auch die Übersichtspolygonresultate aller dieser Schritte enthält also möchte ich diese 3 Polylinien in einer Karte zeichnen, um die Hauptroute und die Alternativen zu sehen, weißt du, wie das geht?Google Maps API: Zeichnen Sie eine Route mit Punkten einer Polylinie

Dies ist eine der Übersicht Polylinien

"overview_polyline": { 
    "points": "uiyqBfb~zQgGwAgCtM}[email protected]_BzSiJxZcBfHuS~NqK`[email protected]{fAoDcW~BmEbBeqAmIaEoBgB{KB}J}[email protected]}EhG{GjAgVcDsN{[email protected]|FaAvOiE|Va`@[email protected]}Jh][email protected]@fGdDxE|O~E~ZzH`ThQtdA|jA|[email protected][iEd`@[email protected]@[email protected]~VnOn][email protected]@|[email protected]_CtBqI?eDhAeGeDsIRyK`IqIfIkPtEuUbNcLpOuPpZ]rHpHtQpLnOlEvIEpJfId[[email protected]@[email protected]@yNnGk`@rVsLfLm|@v|@_VxKgZ`XmR~VeH~^[email protected][email protected]}[email protected]`YqBt[[email protected]|[email protected]@pG{@[email protected]}PhBUhIcD`[email protected]^|Ck}@tFcMjDiP~GeN`RcF]}[email protected]{BvAoGdCsKpFmOgEuB\\eEjKjB~GwGvBiDsDgEyGwD`[email protected]{@rC_CJuHoIiFEgBwC{[email protected]@[email protected]@mCxD{DkAwMrDcJrF}IhSsDbB{D{AyY_CoK~AuP`@[email protected]}[email protected][email protected]@[email protected]}CmHG{KiCyO}P}IgNkNaUoKkCkDYiB{[email protected]}PY{KaEeIBqTfEiEeEgDkLyUyIkT}BoP{DyGiGwHiW{Is^kOiScLmTeIqGsPcTqD_FgMaDwNqMwOuVqHy\\[email protected]_CiBoSpDyHBkH}Kc[kTq[mPyYiOyVyR_Sc\\{ZsRwfA{][email protected]~AqAhEwNgDiNmFgL~H}[email protected]{DRsFqG_FoA}[email protected]}[email protected]@w[cCwH~AeGeFeLcUD_LkAiDwUaJuMXaQuGyBgB|LkLhL{[email protected]}[email protected]{[email protected]]{[email protected]{BxCwC[[email protected]}[email protected]@eIrF{@oG}[email protected]{B{[email protected]@mD\\eMkHkFaJqFkEiPN}HrBvKdEzExA|FJJ" 
    }, 
+0

damit verbundene Frage: [Google Maps statische Karte Zu durch Seen vorbei, Fluss, Berg] (http://stackoverflow.com/questions/32255380/google-maps-static-map-polyline-passing-throug h-lakes-river-mountains) – geocodezip

Antwort

0

Verwenden Sie die decodePath Funktion des geometry library die codierten Punkte zu dekodieren als den Weg einer Polylinie zu verwenden.

var polyline = new google.maps.Polyline({ 
    path: google.maps.geometry.encoding.decodePath(json.overview_polyline.points), 
    map: map 
    }); 

proof of concept fiddle

Code-Schnipsel:

var json = { 
 
    "overview_polyline": { 
 
    "points": "uiyqBfb~zQgGwAgCtM}[email protected]_BzSiJxZcBfHuS~NqK`[email protected]{fAoDcW~BmEbBeqAmIaEoBgB{KB}J}[email protected]}EhG{GjAgVcDsN{[email protected]|FaAvOiE|Va`@[email protected]}Jh][email protected]@fGdDxE|O~E~ZzH`ThQtdA|jA|[email protected][iEd`@[email protected]@[email protected]~VnOn][email protected]@|[email protected]_CtBqI?eDhAeGeDsIRyK`IqIfIkPtEuUbNcLpOuPpZ]rHpHtQpLnOlEvIEpJfId[[email protected]@[email protected]@yNnGk`@rVsLfLm|@v|@_VxKgZ`XmR~VeH~^[email protected][email protected]}[email protected]`YqBt[[email protected]|[email protected]@pG{@[email protected]}PhBUhIcD`[email protected]^|Ck}@tFcMjDiP~GeN`RcF]}[email protected]{BvAoGdCsKpFmOgEuB\\eEjKjB~GwGvBiDsDgEyGwD`[email protected]{@rC_CJuHoIiFEgBwC{[email protected]@[email protected]@mCxD{DkAwMrDcJrF}IhSsDbB{D{AyY_CoK~AuP`@[email protected]}[email protected][email protected]@[email protected]}CmHG{KiCyO}P}IgNkNaUoKkCkDYiB{[email protected]}PY{KaEeIBqTfEiEeEgDkLyUyIkT}BoP{DyGiGwHiW{Is^kOiScLmTeIqGsPcTqD_FgMaDwNqMwOuVqHy\\[email protected]_CiBoSpDyHBkH}Kc[kTq[mPyYiOyVyR_Sc\\{ZsRwfA{][email protected]~AqAhEwNgDiNmFgL~H}[email protected]{DRsFqG_FoA}[email protected]}[email protected]@w[cCwH~AeGeFeLcUD_LkAiDwUaJuMXaQuGyBgB|LkLhL{[email protected]}[email protected]{[email protected]]{[email protected]{BxCwC[[email protected]}[email protected]@eIrF{@oG}[email protected]{B{[email protected]@mD\\eMkHkFaJqFkEiPN}HrBvKdEzExA|FJJ" 
 
    } 
 
}; 
 

 
function initialize() { 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     center: new google.maps.LatLng(37.4419, -122.1419), 
 
     zoom: 13, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
 
    }); 
 
    var polyline = new google.maps.Polyline({ 
 
    path: google.maps.geometry.encoding.decodePath(json.overview_polyline.points), 
 
    map: map 
 
    }); 
 
    var bounds = new google.maps.LatLngBounds(); 
 
    for (var i = 0; i < polyline.getPath().getLength(); i++) { 
 
    bounds.extend(polyline.getPath().getAt(i)); 
 
    } 
 
    map.fitBounds(bounds); 
 
} 
 
google.maps.event.addDomListener(window, "load", initialize);
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script> 
 
<div id="map_canvas"></div>

+0

Danke, es funktioniert perfekt! – SoldierCorp

0

Sie Ihren Weg erklären sollte und dann erklären die Polylinie wie folgt aus:

var flightPlanCoordinates = [ 
    {lat: 37.772, lng: -122.214}, 
    {lat: 21.291, lng: -157.821}, 
    {lat: -18.142, lng: 178.431}, 
    {lat: -27.467, lng: 153.027} 
    ]; 
    var flightPath = new google.maps.Polyline({ 
    path: flightPlanCoordinates, 
    geodesic: true, 
    strokeColor: '#FF0000', 
    strokeOpacity: 1.0, 
    strokeWeight: 2 
    }); 
Verwandte Themen