how to update marker's location when is dragged - android

I have 2 markers one being user's location and the other is a normal draggable marker and i get the distance between them, but no matter where I drag my marker I always get the same distance between them, how can I get an updated location when I drag the marker? Thank you very much

To get the position of the drag marker, you should use an OnMarkerDragListener to listen for drag events on a marker. To set this listener on the map, call GoogleMap.setOnMarkerDragListener.
You can get the position of the marker at any time by calling Marker.getPosition().
Check this issue and SO question for more information.

Related

Why can't I get touch events from a GoogleMap Marker on Android?

I add a marker to the map using the code below, but after doing so I am unable to receive marker click/touch events.
If I just add the marker and don't animate to the marker's location, it seems impossible to click on the marker because of finger accuracy. Every now and then if I tap a lot really fast, I can get a click on it.
But if I do the second step below and animate to the marker's location, I can click on the marker with 100% accuracy, at least once anyway. But what happens is GoogleMap intercepts the touch and I don't get a touch event. Instead, GoogleMap displays two navigation buttons in the lower right corner of the map.
I've attached a screen shot to highlight where I've placed a marker and the navigation buttons that pop up in the lower-right when I touch that marker.
So my question is kinda two-fold. First is can I turn off those navigation buttons and receive that touch event myself?
And secondly, why do I have to animate the map camera to the specified location in order to receive any touch input?
Lastly, is there something I can set so that "fat finger" accuracy is turned on for touching markers? I'd think that unnecessary but maybe it's an issue here?
Also, I do have a Marker click listener. It's just not a direct listener because I have to manage clusters as well.
mClusterManager = new ClusterManager<>(this, mainMap);
mainMap.setOnMarkerClickListener(mClusterManager);
mClusterManager.setOnClusterItemClickListener(this);
mClusterManager.setOnClusterClickListener(this);
OnClusterItemClickListener() never gets called.
Thanks.
// Add marker - this alone doesn't make it clickable
Marker tempCursor = mainMap.addMarker(new MarkerOptions().position(newLatLng)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin_shadow)));
// Animate to new location - after this you can touch/click it
CameraUpdate up = CameraUpdateFactory.newLatLng(newLatLng);
mainMap.animateCamera(up);

Delete all but one marker in Android Google Maps V2

So I have some places of interests shown to user via markers with respect to their current location (which is also shown as a blue marker on the map).
What I want, is to sustain the location marker on the map, remove all the other markers, and refresh it after certain conditions are met. I was able to do all that except the sustaining user location marker + overlay circle.
I know that there's map.clear(); function but wouldn't it also clear the current location marker? How to achieve what I want to?
Thanks.

How to zoom enough to unfold a cluster with Android Maps Extensions?

Sometimes when markers are really close to each other, it requires many clicks to zoom enough so that the cluster unfolds and shows all the markers individually.
How can I make it so that one click on a cluster always zooms in and unfolds it correctly?
If you wanted to zoom to show all the markers from a single cluster, you could end up showing only some of them. If that's ok with you, here are the steps (e.g. in onMarkerClick):
check if Marker.isCluster
loop over Marker.getMarkers
for every marker call GoogleMap.getMinZoomLevelNotClustered and remember the largest value from the loop
after loop call GoogleMap.animateCamera with some LatLng and the largest zoom value
The problem here is to decide what LatLng to choose. If you choose the one from cluster marker, you could even end up not showing any marker after zoom.
Alternatively you may want to zoom to LatLngBounds created from all the markers in the cluster. This will not make it to show all markers, but for sure you would end up with all markers still hidden somewhere on the screen.

Updating location on map while user moving in Android

I am working on a application where I want to show user location when user is moving. I get user location using custom overlay but when user moves marker jumps from one location to another location which I don't want. Marker must move smoothly. Does anyone done this before??
Please give some example code..
Thank You
Edited:--
After using MyLocationOverlay it doesn't solve my problem but when I implemented LocationListener to my activity it solved my problem as now it is more smooth than previous version. I am checking location for 1 micro second & for 0.00001 meters.
Now When marker moves outside the visible area of map it doesn't show the marker so whenever marker moves outside the current visible area of the map activity itself should center of the map to current location (i.e. to the marker location)..
Thank You
If you want your marker moves smoothly then you have to listen the location at very small time .
Means that you have to set the minimum time and minimum distance for location updates to 0.
so when you get the new location you have to update that location on the map so it will work smoothly.

How to make a Google map drawable of overlay movable/dragging it in Android?

In my application, a marker is positioned on a default position.
Now what I want is that user can drag the marker to any other location.
How to do this?
I can create marker on other location onTap event, but I want to drag the marker.
Is it possible in Android?
chckout following project.Hope its useful.
http://github.com/commonsguy/cw-advandroid/tree/master/Maps/NooYawkTouch/

Categories

Resources