Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect moveCamera is finished on the Google map service?

I want to take a snapshot when moveCamera is finished.

I used both onCamerachange() and onMapLoaded() functions to Googlemap object,

But this callback handler's timing is not fit on my intention.

I want to move camera to what I want, and when loading map is finished, want to take a screnshot.

Who do you guys know about how can I do?

Thank you.

====================================================

+MYSOLUTION

Actually, I want to implement tilesloaded() call back function that is supported on the google map API of the javascript. But, as a result, there is no function which is completely accomplished that function.

OnMapLoaded() callback function is just invoked once when the map is loaded first.

OnCameraChanged() or OnCancallableCallback is invoked before all the tiles are loaded.

So I implemented like below source code

...
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10), this);
...
    @Override
public void onFinish() {
    mapFragment.getMapAsync(this);
}
..
    @Override
public void onMapReady(GoogleMap googleMap) {
    // TODO Auto-generated method stub
    mMap = googleMap;// Add a marker in Sydney and move the camera
    mMap.setOnMapLoadedCallback(this);
}

Now, when the camera is moved, onMapLoaded() is always invoked.

Thank you everybody.

like image 459
Hochan Lee Avatar asked Nov 23 '15 18:11

Hochan Lee


People also ask

How do I move my camera to my current location?

Without clicking any button, how to directly get the current location and move the camera to it. Also, I found that there is a button on the right top of the map. When click on it, it will go to current location.

What is zoom level in Google Map?

The Google Maps API provides map tiles at various zoom levels for map type imagery. Most roadmap imagery is available from zoom levels 0 to 18, for example. Satellite imagery varies more widely as this imagery is not generated, but directly photographed.


1 Answers

You can implement this:

mMap.animateCamera(CameraUpdateFactory.zoomTo(16), 3000, new GoogleMap.CancelableCallback() {
            @Override
            public void onFinish() {
                //Here you can take the snapshot or whatever you want
            }

            @Override
            public void onCancel() {

            }
        });

The most detailed form of this method, GoogleMap.animateCamera(cameraUpdate, duration, callback), offers three arguments:

cameraUpdate

The CameraUpdate describing where to move the camera. callback An object that implements GoogleMap.CancellableCallback. This generalized interface for handling tasks defines two methods onCancel() and onFinished(). For animation, the methods are called in the following circumstances:

onFinish()

Invoked if the animation goes to completion without interruption.

onCancel()

Invoked if the animation is interrupted by calling stopAnimation() or starting a new camera movement.

Alternatively, this can also occur if you call GoogleMap.stopAnimation().

Source: Google Maps Android API Guides

like image 87
Brandon Zamudio Avatar answered Oct 05 '22 15:10

Brandon Zamudio