2017-08-12 15 views
2

Ich habe derzeit eine Google Map in meiner Android App mit Benutzer Standortmarker auf Karte öffnen und wenn Benutzer auf eine Position in der Karte klicken, wird eine blaue Markierung (Zielmarker) mit einer Polylinie zwischen Benutzerstandort angezeigt Marker und Zielmarkierung wie dieses Bild:zeichnen Polylinie auf Straßen in Android

example image

How can i draw this lines in roads ???
ich habe folgenden Code:

@Override 
public void onMapReady(final GoogleMap googleMap) { 
    this.googleMap = googleMap; 
    googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() { 
     @Override 
     public void onMapLongClick(LatLng latLng) { 
      destinationLocation = new Location(LocationManager.GPS_PROVIDER); 
      destinationLocation.setLatitude(latLng.latitude); 
      destinationLocation.setLongitude(latLng.longitude); 
      destinationMarker = googleMap.addMarker(new MarkerOptions().position(latLng).title("your destination").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_destination_marker))); 
      Polyline line = googleMap.addPolyline(new PolylineOptions() 
        .add(new LatLng(userLocation.getLatitude(), 
          userLocation.getLongitude()), new LatLng(destinationLocation.getLatitude(), 
          destinationLocation.getLongitude())).color(Color.BLUE).width(10)); 
     } 
    }); 
} 

Antwort

Verwandte Themen