Android 谷歌地图显示了活动开始的时间

Android 谷歌地图显示了活动开始的时间,android,google-maps,Android,Google Maps,在我的应用程序中,我正在使用google maps v2 api 我有下面的代码,当活动第一次开始时,它显示了整个世界,蓝色的pin显示了我的位置。但是,它不会放大到我的直接位置。然而,每当我在一段时间后再次调用此方法(使用“显示我的位置”按钮),我都会将其缩放到我想要的级别 public void onLocationChanged(Location location) { if(location != null) { double latitude = l

在我的应用程序中,我正在使用google maps v2 api

我有下面的代码,当活动第一次开始时,它显示了整个世界,蓝色的pin显示了我的位置。但是,它不会放大到我的直接位置。然而,每当我在一段时间后再次调用此方法(使用“显示我的位置”按钮),我都会将其缩放到我想要的级别

 public void onLocationChanged(Location location)
{
    if(location != null)
    {

        double latitude = location.getLatitude();
        currentLat = location.getLatitude();

        double longitude = location.getLongitude();
        currentLon = location.getLongitude();

        LatLng latLng = new LatLng(latitude, longitude);

        if(googleMap != null)
        {               
                 googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));   
                 googleMap.animateCamera(CameraUpdateFactory.zoomTo(13));

            LatLngBounds bounds = this.googleMap.getProjection().getVisibleRegion().latLngBounds;

            if (!bounds.contains(new LatLng(location.getLatitude(), location.getLongitude())))
            {
                googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
            }

        }
    }

我想你说的是地图视图的相机位置和缩放级别。以下代码应该可以正常工作,前提是您具有在活动加载时相机应移动到的正确lat和long:

CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(17.385044,78.486671)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
您可以从本教程中学到很多东西: