How to detect Google MapView movement in Android? - android

I'd like to dynamically update the map/ load new map overlays every time my user moves it a certain amount of distance. How do I go about doing this? Is there a listener for every time the user moves the map? Most likely I'd just measure the distance between the center points.
Thanks!

Try this to detect the map movements:
http://pa.rezendi.com/2010/03/responding-to-zooms-and-pans-in.html
On start and after the map has been moved, you should save the current map center. As the article suggests, track ACTION_UP to determine when the user has finished a map movement. Then, compare the new map center with the old map center. To get the map centers use MapView's getMapCenter():
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html#getMapCenter()
EDIT: I have done some additional work on this, and have a complete application with code for your enjoyment. This blog post explains a timer solution to this and contains a link to Github source:
http://bricolsoftconsulting.com/extending-mapview-to-add-a-change-event/

The map interface unfortunately does not include any listeners to monitor map actions (zoom/pan). You'll need to set up a timer of some sort that checks the center/zoom levesl to figure out if things have changed and update accordingly.

You could do this by overriding the onTouch(...) method in your Activity (so that every time the user pans the map, you could recalculate the map boundaries). You would need to know the map's zoom level and boundaries, etc, in order to load these overlays based on map distances.

Related

How to eliminate colliding markers in Google Maps

I should show a set of markers on map to indicate nearby points of interest. These markers will open public chat rooms by click and therefore I think the users should see short address information about each marker before entering that room without the need to click on the marker. However, if I change marker icons in that sense, some of the markers may collide as you can see below:
What I want to do is showing as many as possible markers without collision and replace the icon of these colliding ones with a very small marker like a dot (and no address information):
I achieved to get this result by performing x-axis sweep algorithm to detect collisions but unfortunately, if a marker stops colliding after the user scrolls the map or it exists from the screen or another markers enters the screens and begins to collide with other markers or the user scrolls to a completely new area,.. this algorithm should be performed again and again at every turn. To eliminate the majority of colliding markers I make use of maps-utils marker clustering but I need a more painstaking methodology to overcome this issue. I consider to implement quadtree but I could not be sure whether it is the best way or not. Any advice?
Example:
IMHO, the best way could be combining zoom level, quad-tree and collision detection. So, in this scenario
Here, quad-tree will be used to reduce size of items(markers) to be performed collision detection algorithm. Because you should interest with only near markers, not whole markers individually.
If you detect colliding items by zoom level (not for only visible region/bounds as you did), you will not face the problems related below
if a marker stops colliding after the user scrolls the map or it exists from the screen or another markers enters the screens and begins to collide with other markers or the user scrolls to a completely new area
Google Maps Android Marker Clustering Utility from
https://developers.google.com/maps/documentation/android-api/utility/marker-clustering does this.
You can try to remove:
mGoogleMap.setMyLocationEnabled(true);

Drawing on the MapFragment, while keeping some elements visible

I'm developing an application that has the following goal:
Using the google maps android API 2 I get my current position, and as I start walking the application starts drawing the route I take
The twist is that the map is a "blind" map. Meaning the map is hidden, only the Marker of my current position and a dotted line of my route is shown.
Keep in mind I'm a novice developing to Android, so please be specific. (Thank you)
I managed to create the map, get my current position and zoom in to it (Had no sens to see the whole planet while i want only my current position). And it's pretty accurate so far.
The thing is I don't know what should I do from this point on.
Basicly I need a white View between the Marker and the real map. Also as I advance that View should always be on, over the MapFragment/MapView. Also I wish to keep the zoom and drag functionality's of the MapFragment.
How can I achieve this?
At this point I'm opened to any solutions.
(Been browsing for a few days now the developers site, I have seen that with the ViewOverlay class I can put messages over the map, but I'm not sure what would the correct aproach be in my case...)
To hide the whole map behind the white view I would use Polygon class Polygon Even if you specify Polygon to cover the whole map Markers will be still displayed in front of it and as so user's current position marker will be visible. You also will be able to zoom and drag.
To draw line on map use Polyline class Polyline It will draw users path as a polyline. If you want to stick with dotted line you can use Circle objects to create it. Circle

Android - Dragging marker without having to hold in map api v2

I'm implementing a feature in my app that allows user to manually locate themselves on a map. So I use a pin to represent their location and let user drag it to the place they currently are. The simple solution is to use setDraggable(true) on the marker, but this requires users to hold the marker for 3 or 5 seconds until it is draggable. I think this is quite confusing for many user to use the feature. So, what I want is to make the dragging more responsive by letting users drag them immediately without having to hold it for a while - like how Foursquare does!
What should I do to implement my own dragging feature? If you have any suggestions, please help me and thanks.
Check out the Hailo application. They have a neat workaround for this. It only works when you have one marker to drag.
The trick is to pan the map, instead of moving the marker. They just keep the marker in a view on top of the MapFragment (it's not actually a Marker on the map).
You can then use the map's cameraPosition.target as the location of your marker.

how to detect what triggered an android sdk onCameraChange call

I have an application that tracks current location (using LocationListener), continually updating LatLngBounds to keep the track in view. Every time the boundary change causes the map to be redrawn this makes a call to 'onCameraChange'
I want to temporarily halt this process when the user manually expands the map but to do this I need to be able to differentiate between a call to onCameraChange caused by the new LatLngBounds and a call to onCameraChange caused by the manual expansion of the map.
At the moment the onCameraChangeListener is started during the onCreate process.
How can I do that?
You may use a code similar to this issue comment #21.
Thanks for that, it pointed me in the direction to solve the problem.
As it happens, I only want to capture manual input when the user expands the map and so it was quite easy to check the zoom level whenever onCameraChange is called. If the zoom passed by OnCameraChange is greater than the currently recorded zoom then I can be reasonably sure that the user expanded it as a LatLngBounds change will only reduce the zoom level.

Zooming and directions services

I’m looking to force Google direction service to zoom to the final destination rather than show the entire route. Is this possible? If so how would you go about doing this? I would also like to remove the markers I set once the start and end locations have been set and the calculate route function is called is this possible? I don’t think any of the code will help it’s done in v3. I have been searching and found nothing related to the zoom issue. Can anyone please help…
Well this did help, now looking at it hough, i think maybe should have add my code. i'm going to try it in here first. I would like the "A" & "B" markers to stay i have built arrays for othere markers that i would like to suppress once the calculateroute function is handeld or have a button that turns them on and off that wont clear the map or add additional turn by turn directions.
First pass these options when intializing the directionsRenderer:
{suppressMarkers:true,preserveViewport:true}
...so you will not get markers and the map will not fit to the bounds of the route when rendering.
Then, after rendering the route( setDirections() ), call this:
directionsDisplay.setDirections(response);
//set the center of the map to the end of the route
map.setCenter(response.routes[0].legs[response.routes[0].legs.length-1].end_location);
//set the zoom to the desired value
(where directionsDisplay is the directionsRenderer-instance)

Categories

Resources