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.
Related
I made polygon on maps fill black and tried to clear current location use addHole method.
But if holes overlap each other, polygon with holes appear i don't want!
Please give me answer...
http://i.stack.imgur.com/jn15M.jpg
http://i.stack.imgur.com/RajLA.jpg
Plus, Is there exist a way clear the polygon given gps coordinate??
Thanks
You can use TileOverlay.remove() method to remove a tile overlay or use tileOverlay.clearTileCache(); to force a refresh. This will cause all the tiles on this overlay to be reloaded. If the tiles provided by the TileProvider change, you must call clearTileCache() afterwards to ensure that the previous tiles are no longer rendered.
In this Android Design in Action video, they recommend dissabling automatic panning when the info window on a map fits the screen to prevent the touch targets to change each time the user touches a marker. However, I have not found any example on how to do that.
What is the best way to do this?
You may suppress the default panning behaviour by setting your GoogleMap.OnMarkerClickListener and returning true (handled) there. You will have to call marker.showInfoWindow() to still show the info window.
Making this conditional is a bit harder. Most likely you will have to use InfoWindowAdapter and layout View before returning it yourself, using its width, height, LatLng of the Marker converted to Point on screen to calculate if it will fit the screen.
You may also post a feature request on gmaps-api-issues for that. Such conditional default behaviour would be better UX and they got all the data to make this calculation simpler.
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)
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.
I need to redraw the overlay after the user zooms.
What is the best way to do this?
I've tried everything I can think of (saving a getZoomLevel() state, overriding onUserInteraction()), nothing actually works.
The problem is, that draw() is being called when the user clicks zoom, so the information my draw method gets (About the map's state) is different from the state after the mapview finishes zooming.
Also, draw() isn't being called at the end of the zoom, so only if I pan the map the overlay is actually being drawn properly.
As nobody has answered this in 7 months, I will write what I ended up doing.
I used a Handler to refresh the map manually after 500ms, it worked alright.
Handler handler;
handler.postDelayed(refreshRoute, 500);
Have you tried calling mapview.postInvalidate() after the zoom?