2017-03-04 2 views
0

Ich sah dies im Web image So habe ich bestätigt, dass es möglich ist, 2 verschiedene Polylinien in einem Pfad in Google Maps zu füllen.Polyline auf Straßenrand in Android Google Maps

Um dies zu experimentieren, habe ich versucht, mit diesem Code zunächst nur eine Polylinie hinzuzufügen:

public static void drawEncodedPolyOnMap(String encoded, GoogleMap map) { 
    List<LatLng> points = new ArrayList<>(); 
    int index = 0, len = encoded.length(); 
    int lat = 0, lng = 0; 
    while (index < len) { 
     int b, shift = 0, result = 0; 
     do { 
      b = encoded.charAt(index++) - 63; 
      result |= (b & 0x1f) << shift; 
      shift += 5; 
     } while (b >= 0x20); 
     int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
     lat += dlat; 
     shift = 0; 
     result = 0; 
     do { 
      b = encoded.charAt(index++) - 63; 
      result |= (b & 0x1f) << shift; 
      shift += 5; 
     } while (b >= 0x20); 
     int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
     lng += dlng; 
     LatLng p = new LatLng((((double) lat/1E5)), 
      (((double) lng/1E5))); 
     points.add(p); 
    } 

    map.addPolyline(new PolylineOptions().width(7).color(Color.RED).geodesic(true).addAll(points)); 
} 

Aber es gibt mir nicht die Anzeige, die ich

enter image description here

Grundsätzlich erwartet Mein Fall, Polylinien werden in der Mitte ausgerichtet, obwohl die Markierungen am Rand der Straße sind, der Fall, den ich nicht mag.

Ist es möglich, die Polylinie mit den Markern in Android auszurichten? Wie?

Antwort

0

Es scheint niemand antwortet und ich habe gerade einen Weg gefunden, wie es geht.

Im Grunde habe ich gerade meine drawEncodedPolyOnMap aktualisiert, um Padings zum ursprünglichen LatLng, das von bit shifting zurückgegeben wird, hinzuzufügen. Also hier geht der Code unter

public static void drawEncodedPolyOnMap(String encoded, GoogleMap map, boolean type) { 
    List<LatLng> points = new ArrayList<>(); 
    int index = 0, len = encoded.length(); 
    int lat = 0, lng = 0; 
    while (index < len) { 
     int b, shift = 0, result = 0; 
     do { 
      b = encoded.charAt(index++) - 63; 
      result |= (b & 0x1f) << shift; 
      shift += 5; 
     } while (b >= 0x20); 
     int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
     lat += dlat; 
     shift = 0; 
     result = 0; 
     do { 
      b = encoded.charAt(index++) - 63; 
      result |= (b & 0x1f) << shift; 
      shift += 5; 
     } while (b >= 0x20); 
     int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
     lng += dlng; 
     double newLat = (((double) lat/1E5)); 
     double newLng = (((double) lng/1E5)); 

     if(type){ 
      points.add(new LatLng(newLat+PADDING_LAT, newLng+PADDING_LNG)); 
     }else{ 
      points.add(new LatLng(newLat-PADDING_LAT, newLng-PADDING_LNG)); 
     } 
    } 

    map.addPolyline(new PolylineOptions().width(7).color((type)?Color.RED:Color.GREEN).geodesic(true).addAll(points)); 
} 

Und das ist es. Problem gelöst.