-1
A
回答
0
最後我得到了答案奧拉和尤伯杯應用程序如何做這些..
ArrayList<LatLng> points = new ArrayList<LatLng>();
PolylineOptions polyLineOptions = new PolylineOptions();
points.add(new LatLng(from_latitude,from_longitude));
points.add(new LatLng(to_latitude,to_longitude));
polyLineOptions.width(7 * 1);
polyLineOptions.geodesic(true);
polyLineOptions.color(activity.getResources().getColor(R.color.black));
polyLineOptions.addAll(points);
Polyline polyline = mMap.addPolyline(polyLineOptions);
polyline.setGeodesic(true);
0
可以繪製像下面一個
PolylineOptions rectOptions = new PolylineOptions();
LatLng polLatLng = null;
if (points.size() > 0) {
ArrayList<LatLng> pathPoint = new ArrayList<LatLng>();
for (int k = 0; k < points.size(); k++) {
double polLat = points.get(k).latitude;
double polLng = points.get(k).longitude;
pathPoint.add(new LatLng(polLat, polLng));
polLatLng = new LatLng(polLat, polLng);
}
double startLatitude = points.get(0).latitude;
double startLongitude = points.get(0).longitude;
double endLatitude = points.get(points.size() - 1).latitude;
double endLongitude = points.get(points.size() - 1).longitude;
LatLng start = new LatLng(startLatitude, startLongitude);
LatLng end = new LatLng(endLatitude, endLongitude);
mMap.addMarker(new MarkerOptions().position(start).title("start"));
mMap.addMarker(new MarkerOptions().position(end).title("end"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(polLatLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
rectOptions.addAll(pathPoint);
rectOptions.width(10);
rectOptions.color(Color.BLUE);
mMap.addPolyline(rectOptions);
0
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());
}
});
}
相關問題
- 1. 如何獲取兩個位置之間的路線中心緯度和經度
- 2. 如何根據緯度和經度獲得兩個地點之間的距離?
- 3. 如何計算經度和緯度兩點之間的距離?
- 4. 兩個經緯度之間的距離
- 5. 如何找到緯度/經度/緯度點之間的距離?
- 6. 谷歌地圖API - 獲取經緯度/緯線之間的路線點
- 7. 如何列出位於兩度之間的經度和緯度點
- 8. 測量兩個緯度/經度點之間的距離
- 9. 計算兩個緯度 - 經度點之間的距離? - 鈦
- 10. 計算兩個緯度/經度點之間的夾角
- 11. 獲取兩個經度緯度點之間的駕駛距離
- 12. 如何快速估算兩個(緯度,經度)點之間的距離?
- 13. 經典ASP中兩個緯度/長點之間的距離
- 14. PHP兩點之間的距離緯度經度
- 15. 計算兩點之間的距離(經度,緯度)
- 16. 如何獲得谷歌地圖的兩個地方之間的緯度經度緯度
- 17. 兩個經度和緯度之間的距離
- 18. 如何將兩個緯度和經度
- 19. 在緯度/經度點之間更多地計算經度和緯度?
- 20. 存儲路線的經度和緯度
- 21. C中2個緯度/經度點之間的方向#
- 22. 如何找到兩個緯度經度的中心點?
- 23. 兩個意圖之間通過緯度和經度
- 24. 給出經度和緯度的兩點的中點
- 25. 如何使用angulajs計算兩個緯度和經度之間的距離?
- 26. 如何檢查兩個緯度和經度coorindates之間的距離?
- 27. 分別計算兩個緯度和兩個經度之間的距離
- 28. 在excel中,如何計算兩組大點與經緯度之間的距離?
- 29. 如何查找給定點的經度和緯度,給定兩個點之間的距離?
- 30. 計算兩個長/經緯度之間的距離
TYPE = 「駕駛」 或 「走」 –
哥哥使用22.970385,72.577455和41.029469,-77.618526和繪製路徑..你不會得到輸出..首先嚐試一下..然後告訴我 –
它爲我工作 –