How to get the current location in Google Maps Android API v2?

前端 未结 13 1166
Happy的楠姐
Happy的楠姐 2020-11-27 12:32

Using

mMap.setMyLocationEnabled(true)

can set the myLocation layer enable.
But the problem is how to get the myLocation when the user

13条回答
  •  天涯浪人
    2020-11-27 13:21

    It will give the current location.

    mMap.setMyLocationEnabled(true);
    Location userLocation = mMap.getMyLocation();
            LatLng myLocation = null;
            if (userLocation != null) {
                myLocation = new LatLng(userLocation.getLatitude(),
                        userLocation.getLongitude());
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation,
                        mMap.getMaxZoomLevel()-5));
    

提交回复
热议问题