Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Google Map Tiles are Loaded

I am showing a Google Map in my Android Activity which extends FragmentActivity. The map is loaded from the xml layout as follows:

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ad_layout"
class="com.google.android.gms.maps.SupportMapFragment" />

The user can perform certain functions on the map only if the map tiles have finished downloading. Is there a way to determine if the map tiles have finished downloading and are visible - besides obviously looking at the map?

like image 276
user1608385 Avatar asked Mar 15 '26 07:03

user1608385


2 Answers

Set an onCameraChangeListener this will be fired off when the map has finished loading. Do whatever you wish to do then remove the listener so that it only happens once.

map.setOnCameraChangeListener(new OnCameraChangeListener() {

        @Override
        public void onCameraChange(CameraPosition arg0) {

            //TODO: move camera, do whatever you need to do etc...

            // remove listener so that position is not reset when user touches map
            map.setOnCameraChangeListener(null);
        }
    });
like image 117
zambono Avatar answered Mar 17 '26 19:03

zambono


Add OnMapLoadedCallback Listener to your google map object in your activity/fragment

 googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
            @Override
            public void onMapLoaded() {
                // perform certain functions();
            }
        });

For More Reference: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMapLoadedCallback

like image 31
Sagar Ahuja Avatar answered Mar 17 '26 20:03

Sagar Ahuja