Search code examples
android-maps-v2android-progressbarlocationlistener

Display an "indeterminate progress bar" until my location is shown on the map


I am using onMyLocationChangeLIstener with maps v2. It works perfectly:

 private void setUpMap() {

 GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
                @Override
                public void onMyLocationChange(Location location) {
                    LatLng loc = new LatLng(location.getLatitude(), location.getLongitude());

                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f));

            };

            mMap.setOnMyLocationChangeListener(myLocationChangeListener);
 }

When the activity is starting, the entire map is displayed and when the system finds my location, then shows the zoom marker on the map.

I want to display an "indeterminate progress bar" since the activity began, until it shows my location.

I've been reading about it, but I find a way to do it.

I appreciate any help.

Thanks and regards.


Solution

  • What about put a view on top of the map fragment? you can use FrameLayout to temporarly (it is bad for rendering otherwise) overlap a view with the indeterminate progress. When you receive the location change (your listener) you can check if the framelayout is showing (and if exists), and if so remove it.

    Generally this is not recommended in google guidelines since the location could take minutes to hours to be retrieved (in indoor it can even be not found).