Callback after moveCamera on Google Maps

Asked

Viewed 103 times

2

I have a Pageview that, in one of its Fragments, houses a Mapview with a map in "Lite" mode. Clicking on this map, a second Activity is launched (startActivityForResult) which consists of a complete map, where it is possible to mark a particular location. In the onActivityResult() from Fragment, I select the camera for the position marked on the full map.

I know there is a time until the map is loaded on the specified position and zoom, so I created a spinner on the map with the attribute "Gone" in visibility. When in the onActivityResult, change this attribute dynamically to Visible.

Problem

At some point, I need to inform you that the spinner should get "Gone" again. The question is: where?

What I’ve already tried

I tried to implement some Googlemaps interfaces such as OnMapLoadedCallback and OnMapReadyCallback. OnMapReadyCallback is still called, but not when I want, after moving the camera.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        /*Prevent null pointer when user kill the second activity without having results
          Requestcode is not being checked because there is no more than one request for "startActivityForResults"
        */
        if(data != null) {
            map.clear();
            pbStaticMap.setVisibility(View.VISIBLE);
            Double latitude;
            Double longitude;

            latitude = (Double) data.getExtras().get("lat");
            longitude = (Double) data.getExtras().get("long");

            this.markPosition = new LatLng(latitude, longitude);


            map.addMarker(new MarkerOptions().position(markPosition));
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(markPosition, 15));
        }
    }


map.setOnMapLoadedCallback( new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            pbStaticMap.setVisibility(View.GONE);
            Log.d("MapBorba","->>> chamou onMapLoaded ( NEW CALLBACK)");
        }
    });

1 answer

0

You can use the interface OnCameraChangeListener, which is called every time there is a movement on the map. Inside this callback, you check the visibility of your Spinner just not to change his visibility at all times without need:

seuMapa.setOnCameraChangeListener(new OnCameraChangeListener() {
    @Override
    public void onCameraChange(CameraPosition pos) {
        if (seuSpinner.getVisibility == View.VISIBLE){
            seuSpinner.setVisibility(View.GONE);
        }       
    }
});

Official documentation: http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.OnCameraChangeListener.html

  • thank you so much for your attention. I have tried to make use of this callback. But unfortunately it is called as soon as you receive the position change instruction. That is, I give Gone on the spinner before the map is actually displaying what it should...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.