本文介绍了调整谷歌地图(API第2版)Android中缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我'使用地图API在我的应用程序V2 。我要在地图上显示我的当前位置和目标位置,使得这两个位置都显示在屏幕上(在最大可能的缩放级别)。以下是我已经试过到目前为止...

I'am using maps api v2 in my app. I have to show my current location and target location on the map such that both the locations are visible (at the greatest possible zoom level) on the screen. Here is what i have tried so far...

googleMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapFragment)).getMap();

 if(googleMap != null){

        googleMap.setMyLocationEnabled(true);
        LatLng targetLocationLatLng = new LatLng(modelObject.getLattitude(), modelObject.getLongitude());
        LatLng currentLocationLatLng = new LatLng(this.currentLocationLattitude, this.currentLocationLongitude);
        googleMap.addMarker(new MarkerOptions().position(targetLocationLatLng).title(modelObject.getLocationName()).icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
        LatLngBounds bounds = new LatLngBounds(currentLocationLatLng, targetLocationLatLng);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 3));

    }

应用程序是力量收盘原因如下: java.lang.IllegalStateException: 地图的大小不应该是0。最有可能的,布局还没有发生的地图视图。

App is force closing due to the following :java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view.

我怎样才能获得最大可能的缩放级别?请帮我。

How can i get max possible zoom level? Please help me.

推荐答案

在我的项目中,我使用<$c$c>com.google.android.gms.maps.model.LatLngBounds.Builder

In my project I use the com.google.android.gms.maps.model.LatLngBounds.Builder

适合您的源$ C ​​$ C就应该是这个样子:

Adapted to your source code it should look something like this:

Builder boundsBuilder = new LatLngBounds.Builder();
boundsBuilder.include(currentLocationLatLng);
boundsBuilder.include(targetLocationLatLng);
// pan to see all markers on map:
LatLngBounds bounds = boundsBuilder.build();
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 3));

这篇关于调整谷歌地图(API第2版)Android中缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:49