I’m trying to write an Android app that will allow a user to search for a generic destination (e.g., “gas station”) and be presented with up to ~5 nearby locations to choose from. The screen results would display the user location in the center, and possible destination options would be indicated by markers.
The trick is that I don’t want to rescale the map from its starting scale, and so some of the possible destinations may not be visible on the screen. I want to dynamically draw a clickable direction indicator (such as an arrow) that emanates from the user location and points to any off-screen destination. If there are multiple off-screen destinations, I’d probably want to scale the arrow lengths to indicate relative distances. If the user clicks on the arrow, they should be “teleported” to the off-screen location.
Any thoughts on how to best implement this? The only information I’ve found on overlays uses static files (Most overlays seem to be just .PNG files for markers; one example had a route that was drawn from an XML file). I’d need to calculate the arrow based on direction
to the destination (direction the arrow points) and the relative distance to that location (arrow length), so the overlay is something I’d have to come up with at run time.
I think the main challenge is drawing the clickable arrows, but another question that comes to mind is, should I search using the Google Maps API, or is this job more suited to the Google Places API?
Thanks!
A dynamically-drawn, clickable overlay is merely a subclass of
Overlay. You will override one or both of thedraw()methods to render your arrows using theCanvas2D drawing API. You will overrideonTap()to be notified of taps on the map, to see if they tapped on an arrow. You add the overlay to theMapViewviaaddOverlays().add().Those are usually
ItemizedOverlayclasses. That’s much simpler to implement, particularly if you are one of those developers (like me) who is all thumbs when it comes toCanvas. However, you cannot achieve what you want with anItemizedOverlay, in all likelihood.Correct. You can use a
Projectionto help convert between pixel space and geo-space (latitude and longitude), if needed.Note that this all assumes you are trying to use
MapActivityandMapView. You are also welcome to useWebViewor a plain browser to bring up your own JavaScript-based maps, if you prefer.