0
A
回答
0
我想你使用的是折线这样
绘制你的路,所以我说的功能,所以我现在缩小基于之间的距离来计算距离
private class ParserTask extends AsyncTask<String,Integer,List<List<HashMap<String,String>>>>{
JSONObject jsonObject;
List<List<HashMap<String,String>>> routes=null;
@Override
protected List<List<HashMap<String, String>>> doInBackground(String... jsonData) {
try {
jsonObject=new JSONObject(jsonData[0]);
PathJsonParser pathJsonParser=new PathJsonParser();
routes=pathJsonParser.parse(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
return routes;
}
@Override
protected void onPostExecute(List<List<HashMap<String, String>>> lists) {
ArrayList<LatLng> points = null;
PolylineOptions polyLineOptions = null;
if(routes.size()>0){
// traversing through routes
for (int i = 0; i < routes.size(); i++) {
points = new ArrayList<LatLng>();
polyLineOptions = new PolylineOptions();
List<HashMap<String, String>> path = routes.get(i);
for (int j = 0; j < path.size(); j++) {
HashMap<String, String> point = path.get(j);
double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);
points.add(position);
}
polyLineOptions.addAll(points);
polyLineOptions.width(10);
polyLineOptions.color(Color.BLUE);
}
}
if(null!=polyLineOptions) {
mMap.addPolyline(polyLineOptions);
float totalDistance = 0;
for(int k = 1; k < polyLineOptions.getPoints().size(); k++) {
Location currLocation = new Location("this");
currLocation.setLatitude(polyLineOptions.getPoints().get(k).latitude);
currLocation.setLongitude(polyLineOptions.getPoints().get(k).longitude);
Location lastLocation = new Location("that");
lastLocation.setLatitude(polyLineOptions.getPoints().get(k-1).latitude);
lastLocation.setLongitude(polyLineOptions.getPoints().get(k-1).longitude);
totalDistance += lastLocation.distanceTo(currLocation);
}
DISTANCE_BETWEEN= (int) (totalDistance/1000);
}
}
}
,我缩小从这两点的中点开始
LatLng x = new LatLng((LOCATION_FROM.latitude + LOCATION_TO.latitude)/2, (LOCATION_FROM.longitude + LOCATION_TO.longitude)/2);
mMap.resetMinMaxZoomPreference();
if (DISTANCE_BETWEEN < 30) {
CAMERA_ZOOM = 8;
} else if (DISTANCE_BETWEEN > 30 && DISTANCE_BETWEEN < 60) {
CAMERA_ZOOM = 6;
} else {
CAMERA_ZOOM = 4;
}
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(x, CAMERA_ZOOM);
mMap.animateCamera(cameraUpdate);
相关问题
- 1. 如何在android imageview上显示静态谷歌地图?
- 2. 谷歌静态地图不显示
- 3. 谷歌静态地图显示折线使用编码路线
- 4. 如何在webview中显示谷歌地图导航地址android
- 5. 如何离线显示谷歌地图?
- 6. 显示谷歌地图中的航迹
- 7. 谷歌静态地图图像未显示在Firefox
- 8. 如何静态谷歌地图
- 9. 显示在谷歌地图上的Android
- 10. 在Android的谷歌地图显示textview
- 11. Access 2010中显示谷歌的静态地图图像
- 12. 在Android谷歌地图中显示折线完全像手机中的谷歌地图应用程序
- 13. android谷歌地图导航
- 14. 静态谷歌地图不显示在iOS7.1上
- 15. 标记不显示在静态谷歌地图
- 16. 在android中显示谷歌地图webview
- 17. 谷歌地图不显示在Android
- 18. 如何在谷歌地图中直观地显示路线
- 19. 如何在android中的webview中显示本地谷歌地图?
- 20. 谷歌静态地图只显示img图标
- 21. 如何显示在谷歌地图
- 22. 谷歌地图不能全幅显示
- 23. 谷歌地图api 2如何显示/隐藏谷歌地图?
- 24. 显示在谷歌地图
- 25. Android谷歌地图显示为图片
- 26. 多段线不显示(谷歌地图)
- 27. 谷歌地图不显示路线
- 28. 谷歌地图显示路线
- 29. 谷歌地图API显示折线
- 30. android:显示谷歌地图的方向
您可以使用可见参数定义静态地图的视口。 详情请参阅文档: https://developers.google.com/maps/documentation/static-maps/intro#Viewports – xomena
我有同样的问题,这就是我所做的:1.我添加了拉脱维亚人,然后平均得到中点。 2.然后我计算两点之间的距离3.然后我使用轨迹方法根据距离之间的距离创建最佳缩放级别。因此,我有一个switch语句根据点之间的距离选择缩放级别。然后,我在摄像头上应用摄像头缩放 – Mushirih
@PeterMushirih你可以举一些例子或者解释一些。 –