MapView multitouch zoom vs. built-in zoom controls - android

I'm trying to solve the following problem with MapView in an Android aplication:
I draw a static overlay over the map, it's position is relative to screen top and I use its (x,y) point to detect and reverse geocode a location underneath it.
When I zoom using built-in zoom controls, the map center position is not changed and consequently the address marker points to is also the same regardless of zoom level.
However, when I zoom via multitouch, the map center is moved aside and in result my marker points to a new address after the zoom is finished.
Can someone please suggest a solution on how to stick to the same address when zooming the map via multitouch?
Thanks

Related

Adding markers to google map 2 depending on the zoom level

I have multiple markers set around on the map. What I want to know is how can I show only a few markers depending on the zoom level. For example: I have a zoom on the map with radius: the length between the center of the map and the bounds of the screen (lets say this is like 2km in real life not sure if this is true) so I want to show only the markers that are inside the radius. And of course if the user zooms out the radius will be recalculated again from the center point of the map to the bound of the screen. And again include markers that are inside the new radius. How can I achieve this?
I have thought about this problem and here could be an approach.
you can loop through your available markers and find distance from the center of your given circle (since we're talking about a radius) to the marker; this can be done using computeDistanceBetween(); for more info see link
If the marker lies within your radius, show, otherwise, hide using the setVisible() method. For more information, see link
Hope this gives you some idea.

Android google maps zoom to fit mark and current position

I'm trying to create a custom "my location" button for my app using Google Maps.
What I'm trying to do is to center the map around the location of the user, which is already done and working flawlessly, but also want to zoom in just enough to see a marker of my choice (this is actually the closest of a set of markers I have in memory, but that's not important now).
I haven't been able to find how the zoom variable works here. If I know the marker I want to show is 0.5 GPS units away from me, how can I center the map around me in a way that includes that marker on its boundaries? I'd also use a padding to make sure it perfectly fits in the map.
LatLng my_coordinates = ...;
LatLng closest_mark = ...;
map.animateCamera(CameraUpdateFactory.newLatLng(my_coordinates));
So now I want to modify that code to not only center the position to my_coordinates but also make sure zoom will make closest_mark fit in the viewport
CameraUpdateFactory.newLatLngBounds( ?? , /*padding*/);
I don't think there is a specific zoom variable in the api you can control along with the points in the map. (And LatLngBounds just takes in the upper right and lower left bounds and gets you a view accordingly).
I believe what you could do is with a little geometry. If your marker is very close to your location (you can consider it a rectangle), get the distance between the two and extrapolate that on the opposite direction with the same distance (multiple by a small factor if you want some padding) to get the other coordinates, and then you can get the upper right and lower left coordinates (simple geometry).
If your marker is quite far and the surface of the earth comes into picture, you may have to use the haversine formula (great circle distance).
Hope this helps.

Smooth zoom in Android MapView?

I have a MapView with one overlay. Overlay renders tile based map over the MapView. I use MapView.getZoomLevel() to retrieve current zoom level for Google map and for my tiles. Everything works just perfect, but only if user don't zoom the map using multitouch gestures. As I understand, the MapView control don't render actual tiles during zooming process, but just show stretched screen content. So, the question is - How to get this scale ratio which I can use to render my tiles exactly in same way as Google do?
Thank You!
Although the method MapView.getZoomLevel() isn't aligned with zoom changes animation and multitouche, the methods MapView.getProjection().fromPixels() and MapView.getProjection().fromPixels() are.
So you have several option to adress the issue. From the methos above, you can find the direct (x,y) coordinates (and size) where to render the tiles or you can find the zoom ration using something like:
int lonSpan = projection.fromPixels(0,mapView.getHeight()/2).getLongitudeE6() -
projection.fromPixels(mapView.getWidth(),mapView.getHeight()/2).getLongitudeE6();
which gives you the longitude span at map vertical center. Then, you divide the value after zoom starts from the value before zoom starts.
Regards.

Android-Adjusting the zoom controls

In my google maps activity,the map is shown based on the current position.So i need to adjust the zoom controls of the map so that my current point and target point is always visible in the map.I think i need to be more specific.ie,I have a target address that is shown by an overlay image.My current position is focused on the map.So as I move away from the target,I need to adjust the zoom controls so that the target is still visible.Similarly,When I move close to target,I need to zoom in.
Check this answer here they have given code to zoom to the level to show each Overlay Marker drawn on the map so each of them are visible..may be this can solve your problem
LINK TO THE QUESTION
Use the following methods of MapView:
mapView.getController().setZoom(13); // set the zoom level here
mapView.getController().setCenter(point);
where mapview is the instance of MapView.
Hope this is what you want.

Arrows on map with google maps API

I am using the google maps api for an android game that incorporates the players movement in the real world. I have figured out how to make markers indicating where something would be on the map, but I would like to keep a fixed map zoom level and have off-screen markers show up as arrows on the screen.
Anyone know of a way inside of the map API to do this without having to explicitly figuring out the angle to the object and rotating an arrow icon to point in that direction.
I don't have experience of the Google API, but from a simple point of view if you know the current location and the marker location couldn't you just use some simple vector maths to calculate the heading and, therefore, the arrow heading?
i.e.
MarkerPosition - CurrentPosition = TargetVector
TargetVector.normalize()

Categories

Resources