如何缩放相机以覆盖android googlemap中的路径? [英] How to zoom camera to cover the path in android googlemap?

查看:157
本文介绍了如何缩放相机以覆盖android googlemap中的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 LatLng.Builder 覆盖了 Google map 中的多个位置,并且它正在工作。
是否有任何方法可以覆盖 Google地图中的两个位置之间的整个路径?



我的Curent Code包含多个位置

  builder = new LatLngBounds.Builder(); 
builder.include(LatLng1);
builder.include(LatLng2);
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(),17));

有什么建议吗?

谢谢
<解决方案很简单



如果要寻找这种功能,这可能有助于未来的人。 $ b

这个方法在 google方向API 返回从位置A到乙 directionPoints 是路线中点的列表



<$ (ArrayList< LatLng> directionPoints)
{
PolylineOptions rectLine = new PolylineOptions()。width(3).color(Color.RED); p pre> public void handleResult
for(int i = 0; i< directionPoints.size(); i ++)
{
rectLine.add(directionPoints.get(i));
}

//这条多段线被存储起来,所以如果需要的话可以通过调用drawnRoutePath.remove()来删除它
drawnRoutePath = googleMap.addPolyline(rectLine);
prepareBuilder(directionPoints);
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(),17));
}

更新
$ b

来自Google方向API的json响应

 routes:[
{
bounds:{
northeast:{
lat:27.7136953,
lng:85.32216629999999
},
southwest: {
lat:27.7103725,
lng:85.3214952
}
},
....等

所以我用这个边界的 lat lng LatLngBounds.Builder 。

  JSONObject jsonBound = ((的JSONObject)jRoutes.get(i))的getJSONObject( 边界)。 
JSONObject jsonSouthWest = jsonBound.getJSONObject(southwest);
JSONObject jsonNorthEast = jsonBound.getJSONObject(northeast);
LatLng boundSouthWest = new LatLng(jsonSouthWest.getDouble(lat),jsonSouthWest.getDouble(lng));
LatLng boundNorthEast = new LatLng(jsonNorthEast.getDouble(lat),jsonNorthEast.getDouble(lng));
ArrayList< LatLng> bounds = new ArrayList< LatLng>();
bounds.add(boundNorthEast);
bounds.add(boundSouthWest);

并包含在 LatLngBounds.Builder

I have covered multiple locations in Google map using LatLng.Builder and it's working. Is there any way I could cover the whole path between two location in Google map?

My Curent Code to include multiple locations

builder = new LatLngBounds.Builder();
builder.include(LatLng1);
builder.include(LatLng2);
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 17));

Any suggestion please?
Thanks

解决方案

The solution was simple

This might help someone in the future if looking for this sort of feature.

This method is called after the google direction API returns the route from location A to B. directionPoints is the list of Points in the route.

public void handleResult(ArrayList<LatLng> directionPoints)
    {
        PolylineOptions rectLine = new PolylineOptions().width(3).color(Color.RED);
        for(int i = 0 ; i < directionPoints.size() ; i++)
        {
            rectLine.add(directionPoints.get(i));
        }

        //this polyline is stored so that it can be removed by calling drawnRoutePath.remove() if needed
        drawnRoutePath = googleMap.addPolyline(rectLine);
        prepareBuilder(directionPoints);
        googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 17));
    }

UPDATE

The json response from the Google Direction API

"routes" : [
      {
         "bounds" : {
            "northeast" : {
               "lat" : 27.7136953,
               "lng" : 85.32216629999999
            },
            "southwest" : {
               "lat" : 27.7103725,
               "lng" : 85.3214952
            }
         },
.... etc

So I used this bound's lat and lng as parameter to LatLngBounds.Builder.

JSONObject jsonBound = ((JSONObject)jRoutes.get(i)).getJSONObject("bounds");
JSONObject jsonSouthWest = jsonBound.getJSONObject("southwest");
JSONObject jsonNorthEast = jsonBound.getJSONObject("northeast");
LatLng boundSouthWest = new LatLng(jsonSouthWest.getDouble("lat"),jsonSouthWest.getDouble("lng"));
LatLng boundNorthEast = new LatLng(jsonNorthEast.getDouble("lat"),jsonNorthEast.getDouble("lng"));
ArrayList<LatLng> bounds = new ArrayList<LatLng>();
bounds.add(boundNorthEast);
bounds.add(boundSouthWest);

and included these points in LatLngBounds.Builder

这篇关于如何缩放相机以覆盖android googlemap中的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆