I have been working on an android application which uses Google map.Now I want to generate the path (driving direction) between 2 points on the map,how can this be done?
Asked
Active
Viewed 3.7k times
0
-
2Go to this: [http://stackoverflow.com/questions/2176397/drawing-a-line-path-on-google-maps?rq=1](http://stackoverflow.com/questions/2176397/drawing-a-line-path-on-google-maps?rq=1) – M D Jan 16 '14 at 06:29
-
Check this https://stackoverflow.com/questions/47492459/android-google-maps-draw-a-route-between-two-points-along-the-road/52424251#52424251 – B-GangsteR Sep 20 '18 at 11:37
2 Answers
4
you can use the latest google api
http://developer.android.com/google/play-services/maps.html
thre are lot of links available for this. take a look on
Drawing a line/path on Google Maps
How to Draw Route in Google Maps API V2 from my location
Android: How to draw route directions google maps API V2 from current location to destination

Community
- 1
- 1

Connecting life with Android
- 3,846
- 4
- 24
- 38
0
public void DrawLine(LatLng location){
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.add(location)
.add(new LatLng(mlatitude, mlongitude))
.add(new LatLng(mlatitudeEnd,mlongitudeEND));
mMap.addPolyline(polylineOptions);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
}
protected void placeMarkerOnMap(LatLng location){
MarkerOptions markerOptions=new MarkerOptions().position(location);
String str_getloc = getAddress(location);
markerOptions.title(str_getloc);
mMap.addMarker(markerOptions);
}
private String getAddress(LatLng location){
Geocoder geocoder=new Geocoder(this);
String addresstxt="";
List<Address> addresses=null;
Address address=null;
try {
addresses=geocoder.getFromLocation(location.latitude,location.longitude,1);
//addresstxt= String.valueOf((new LatLng(mlatitude,mlongitude)));
//addresses.add(addresstxt)
if (null != addresses && !addresses.isEmpty() ){
address=addresses.get(0);
for (int i=0; i<address.getMaxAddressLineIndex();i++){
addresstxt += (i==0) ?address.getAddressLine(i): ("\n"+address.getAddressLine(i));
}
if (mlatitudeEnd!=0.0&&mlongitudeEND!=0.0){
Toast.makeText(this, "if", Toast.LENGTH_SHORT).show();
// DrawLine(new LatLng(mlatitude,mlongitude));
DrawLine(location);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return addresstxt;
}

vishal yadav
- 1
- 1
-
1Thanks for sharing your answer. Can you please add an explanation or some comments to it? – shapiro yaacov Feb 08 '17 at 12:27