【问题标题】:Google Map V2 how to set ZoomToSpan?Google Map V2如何设置ZoomToSpan?
【发布时间】:2015-02-14 01:58:17
【问题描述】:

作为标题,在地图 v1 中我可以使用

mapController.zoomToSpan(..., ..., ...);

在屏幕上包含所有标记。

Dose map V2有同样的方法吗?


2013/2/22 编辑:

首先,获取您想要在屏幕上涉及的所有 LatLng 点。

假设您有 3 个 LatLng 点,请使用

LatLngBounds bounds = new LatLngBounds.Builder().include(point1)
                    .include(point2).include(point3).build();

mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));

【问题讨论】:

  • 你有没有得到这个答案?我也找不到 ZoomToSpan 等价物。
  • 移动您的编辑以回答并接受它。有些用户似乎不明白你自己回答了。

标签: android


【解决方案1】:

试试这个

  map.addMarker(new MarkerOptions().position(latlng)).setVisible(true);

  // Move the camera instantly to location with a zoom of 15.
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15));

  // Zoom in, animating the camera.
  map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);

【讨论】:

    【解决方案2】:

    我希望这对你有用。

    public class GoogleMapActivity extends FragmentActivity {
    
    private GoogleMap map;
    Bundle extras;
    
    LatLng latlng;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.google);
    
        extras = getIntent().getExtras();
        if (extras != null) {
            unit_long = extras.getString("unit_long");
            unit_lat = extras.getString("unit_lat");
    
        }
    
        latlng = new LatLng(Double.parseDouble("19.25252"),
                Double.parseDouble("23.25252525"));
    
        map = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();
    
        Marker hamburg = map.addMarker(new MarkerOptions().position(latlng)
                .title("Location").snippet("I am here")
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
    
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15));
    
        // Zoom in, animating the camera.use this line in your code 
        map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
        // map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    
    }
    }
    

    【讨论】:

      【解决方案3】:

      地图 V2

       protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
       GoogleMap map = ((SupportMapFragment)getSupportFragmentManager()
                                                  .findFragmentById(R.id.map)).getMap();
       map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      
           if (map != null) {
              // Zoom in, animating the camera.
          map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
           }
       }
      

      你可以改变12的值,即地图加载的缩放级别。 玩得开心!

      【讨论】:

        【解决方案4】:

        Google map V2 的几个方法可以做同样的事情:

        static CameraUpdate  newLatLngBounds(LatLngBounds bounds, int padding)
        

        返回一个 CameraUpdate,它可以转换相机,以使指定的纬度/经度边界以最大可能的缩放级别在屏幕上居中。

        static CameraUpdate newLatLngBounds(LatLngBounds bounds, int width, int height, int padding)
        

        返回一个 CameraUpdate,它转换相机,以使指定的纬度/经度边界在屏幕上以最大可能的缩放级别在指定尺寸的边界框内居中。

        static CameraUpdate  newLatLngZoom(LatLng latLng, float zoom)
        

        返回一个 CameraUpdate,它将屏幕中心移动到由 LatLng 对象指定的纬度和经度,并移动到给定的缩放级别。

        这是使用其中之一的示例:

        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(geoPoint, zoom));
        

        【讨论】:

          猜你喜欢
          • 2012-12-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-08-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多