know google maps stop moving xamarin android - android

I want to update the value of a marker when the maps stop moving, but I canĀ“t detect it. Does someone know how?. I already tried with the PanGestureRecognizer

Implement the GoogleMap.IOnCameraIdleListener and assign it to your map instance (assumably in the MapReady callback):
Implement GoogleMap.IOnCameraIdleListener
public void OnCameraIdle()
{
// a callback that is invoked when camera movement has ended.
}
Assign the Idle listener to the GoogleMap instance:
googleMap.SetOnCameraIdleListener(this);
Re: setOnCameraIdleListener

Related

GoogleMap.OnCameraChangeListener onCameraChange works with delays

I need to listen CameraPosition changes to draw a custom compass. The problem that: GoogleMap.OnCameraChangeListener onCameraChange
this listener may not be notified of intermediate camera positions.
it fires with random delays (can not understand why)
Is there are any way to listen to CameraPosition bearing changes? (In ios f.e. it's possible to achieve using Key-Value Observing), reflection...?
Thanks.
Put FrameLayout above map and catch touches:
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mCatchTouchFrameLayoutListener != null)
mCatchTouchFrameLayoutListener.onTouch(ev);
return false;
}
To move the camera instantly with the given CameraUpdate, you can call GoogleMap.moveCamera(CameraUpdate).
You can make the user experience more pleasing, especially for short moves, by animating the change. To do this instead of calling GoogleMap.moveCamera() call GoogleMap.animateCamera(). The map will move smoothly to the new attributes. 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().
Duration: Desired duration of the animation, in milliseconds, as an int.

How to avoid that the GoogleMap change the camera twice?

this is my first question here:
I'm developing an Android app using Google Maps API and in my main activity I have a fragment with the map. I center the map with the moveCamera method within the event onMapLoaded but the problem is that while the map is loading, it displays the Ecuador and then it switchs to the area I have chosen.
How can I avoid this? I can't invoke moveCamera() outside the event onMapLoaded
Thanks in advance
If you want to keep track of the camera position, you can use an OnCameraChangeListener
which is set on the map by calling GoogleMap.setOnCameraChangeListener(OnCameraChangeListener).
The listener will be notified when the camera changes with an onCameraChange(CameraPosition) callback. You can then obtain the target (latitude/longitude), zoom, bearing and tilt of the camera. This callback is guaranteed to be called at the end of every animation but may not be called for intermediate frames.

How do I find out when the user is being followed by the map or not?

I realise I can use a GoogleMap.OnMyLocationButtonClickListener to determine when the user has pressed the button to make the GoogleMap follow their location on screen, but is there a way I can receive an event for when the user is no longer following the device? For example, if the user has moved the map, which stops the map from locking to the user's location.
You could add a OnCameraChangeListener, it will get called if the map is dragged. In its onCameraChange compare the CameraPosition#target LatLng with MyLocation.
Here are the camera change and my location listeners in the same API:
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.OnCameraChangeListener
https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap.OnMyLocationChangeListener
I suggest using a View overlapping MapFragment and overriding its onTouchEvent, checking DOWN event to stop following position. This is when user starts any interaction with map.

Android Google Map Api V2 OnCameraChangeListener

I am doing a project related to android Google Map Api V2. If I set OnCameraChangeListener on GoogleMap. whenever GoogleMap calls the moveCamera(), the logic in the CameraChangeListener() should be executed?
Yes, your OnCameraChangeListener callback is triggered after you call moveCamera. It may be not called if the call would result in no change, e.g. moving to the same LatLng twice.
As the OnCameraChangeListener Documentation states, the onCameraChange method:
Called after the camera position has changed. During an animation, this listener may not be notified of intermediate camera positions. It is always called for the final position in the animation.
So yest this listener will be invoked on camera position change.

First Android app uses GPS location and maps, but runs battery flat

I have just started working on my first Android application and am going ok. I have managed to get the app to locate my current position on a map and place the blue circle there. I can see the satellite icon in the notification bar working (satellite dish with rays coming off it).
I am very new to android phones altogether but upon being done with my app I just exit it by either using the back key or the home key which works fine, however I notice the satellite icon is still working. Going back to my phone an hour later the GPS is still running. This of course sends the phone battery flat very quickly.
I assume unlike iPhone that Android apps can run in the background and this is still running. How do I get my app to stop using GPS when it is no longer on the map view?
Here is an example of what I have done so far:
//find and initialise map view
private void initMapView() {
map = (MapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(false);
map.setBuiltInZoomControls(true);
}
//start tracking the position on the map
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
//overlay.enableCompass(); does not work in emulator
overlay.runOnFirstFix(new Runnable() {
public void run() {
//zoom in to current location
controller.setZoom(8);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
Do I need to disable something when I leave the map view? if so, how?
Cheers guys
You should probably take a look at the Activity Lifecycle. In short, your assumption is correct: Android does not just kill your App when you leave it.
You'll have to implement the onPause() method and unregister the GPS listener. And maybe also remove the mapview, but I don't think that matters much in terms of battery life.
Also, you should move the registration of the GPS into the onResume() method. That's necessary in order to enable the GPS again when your App coms back into view.
The onPause(), onResume(), onCreate() (and so on) methods get called by android itself at the appropriate times.
Daniel,
Within the maps overlay API there are function calls that will register and unregister the listener for you...
You are already calling the enableMyLocation(); now you need to call overlay.disableMyLocation();
In the onPause.

Categories

Resources