Callback after moveCamera in Google Maps

2

I have a PageView that, in one of your Fragments, houses a MapView with a map in "Lite" mode. Clicking on this map launches a second activity ( startActivityForResult ) that is composed of a complete map, where it is possible to mark a certain location. In%% of the fragment, I set the camera to the position marked in the complete 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 "Gone" attribute in visibility. When in onActivityResult() , I change this attribute dynamically to onActivityResult .

Problem

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

What I've tried

I tried to implement some GoogleMaps interfaces, such as Visible and OnMapLoadedCallback . OnMapReadyCallback is still called, but not when I want it, 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)");
        }
    });
    
asked by anonymous 04.03.2015 / 06:45

1 answer

0

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

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

Official documentation: link

    
04.03.2015 / 11:47