在实时谷歌地图v2中关注用户的位置

时间:2017-01-07 12:00:30

标签: android google-maps google-maps-android-api-2 google-maps-api-2

我希望每次移动时都关注用户的位置,但是当用户移动时,相机不会关注用户的位置。

这是我的onlocationchanged

public void onLocationChanged(Location location) {
    latitude = location.getLatitude();
         longitude = location.getLongitude();
         latLng = new LatLng(location.getLatitude(), location.getLongitude());
        Log.d("onLocationChanged", "entered");

        mLastLocation = location;
        if (mCurrLocationMarker != null) {
            mCurrLocationMarker.remove();
        }

        mMap.getUiSettings().setMyLocationButtonEnabled(false);



        //Place current location marker

        //move map camera
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
        mCurrLocationMarker = mMap.addMarker(new MarkerOptions()
                .position(latLng)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.kikomarke1r11)));
        Toast.makeText(traffic.this, "Your Current Location", Toast.LENGTH_LONG).show();

        Log.d("onLocationChanged", String.format("latitude:%.3f longitude:%.3f", latitude, longitude));

        //stop location updates
        if (mGoogleApiClient != null) {
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
            Log.d("onLocationChanged", "Removing Location Updates");
        }
        Log.d("onLocationChanged", "Exit");
    }

我试图删除:

if (mGoogleApiClient != null) {
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
            Log.d("onLocationChanged", "Removing Location Updates");
        }
        Log.d("onLocationChanged", "Exit");

但是当我移除它时,我成功地将相机聚焦到用户移动时的用户位置,它的缺点是,相机不断更新到用户的位置,即使用户是不动了

0 个答案:

没有答案