onLocationChanged即使在刚刚移动地图时也被调用

问题描述 投票:0回答:1
locationListener = new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    centerOnMapLocation(location,"Your location");
                }

仅在仿真器中从onLocationChanged的i 设置位置,即更改用户位置时,才应调用[[此方法extented controls]。

 public void centerOnMapLocation(Location location, String title){
        if(location!=null) {
            LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());
            mMap.clear();
            mMap.addMarker(new MarkerOptions().position(userLocation).title(title));
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 12));
        }
    }

centerOnMapLocation将相机移动到用户所在的位置。当我从仿真器中的extented controls单击设置位置时,摄像机和标记器将移动到新位置。没关系。但是之后,当我尝试在地图中移动时,一旦我停止触摸屏幕,相机就会再次移回标记。

基本上,当我在地图屏幕上滑动以在地图内移动时,只要我的幻灯片停止(意味着我停止触摸屏幕),相机就会再次移至标记。我希望标记保留在那里,并且应该能够像往常一样在地图内移动

为什么当摄像机仅在位置更改时移动而不在地图屏幕更改时移动

android android-maps-v2 android-maps
1个回答
0
投票

以下行提供对locationLister的位置更新。

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);

要求位置更新时的第三个参数是minimum distance,直到位置更新为止。在以上情况下,当传递0时,它将连续更新位置,并且locationLister将其作为新位置,然后cameraZoom将被更新。

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,1,locationListener);

要解决此问题,只需将minimum distance的值更改为任意值,此处为1。现在,在更改位置之前,它不会调用centerOnMapLocation

© www.soinside.com 2019 - 2024. All rights reserved.