solution 1:
private void showDirection(LatLng source, LatLng destination) {
Map<String, String> hashMap = new HashMap<String, String>();
final String url = "http://maps.googleapis.com/maps/api/directions/json?origin="
+ source.latitude
+ ","
+ source.longitude
+ "&destination="
+ destination.latitude
+ ","
+ destination.longitude
+ "&sensor=false";
new HttpRequester(activity, hashMap, StaticValues.ServiceCode.GET_ROUTE, true,
this);
Utils.showCustomProgressDialog(activity,
getString(R.string.text_getting_direction), false, null);
}
solution 2:
private void build_retrofit_and_get_response(String type) {
String url = "https://maps.googleapis.com/maps/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitMaps service = retrofit.create(RetrofitMaps.class);
Call<Example> call = service.getDistanceDuration("metric", StartLocation.latitude + "," + StartLocation.longitude,
EndLocation.latitude + "," + EndLocation.longitude, type);
call.enqueue(new Callback<Example>() {
@Override
public void onResponse(Response<Example> response, Retrofit retrofit) {
try {
//Remove previous line from map
if (line != null) {
line.remove();
}
// This loop will go through all the results and add marker
on each location.
for (int i = 0; i < response.body().getRoutes().size(); i++) {
String distance = response.body().getRoutes().get(i).getLegs().get(i).getDistance().getText();
String time = response.body().getRoutes().get(i).getLegs().get(i).getDuration().getText();
// activity.setTitleActionBar("Distance:" + distance + ", Duration:" + time);
String encodedString = response.body().getRoutes().get(0).getOverviewPolyline().getPoints();
List<LatLng> list = decodePoly(encodedString);
line = mGoogleMap.addPolyline(new PolylineOptions()
.addAll(list)
.width(10)
.color(Color.RED)
.geodesic(true)
);
}
} catch (Exception e) {
Log.d("onResponse", "There is an error");
e.printStackTrace();
}
}
@Override
public void onFailure(Throwable t) {
Log.d("onFailure", t.toString());
}
});
}
type = "Fahren" oder "Walking" –
Bruder verwenden 22,970385, 72,577455 und 41.029469, -77.618526 und zeichnen Pfad .. Sie werden nicht ausgegeben .. zuerst versuchen Sie es..dann sagen Sie mir –
seine Arbeit für mich –