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.
Related
I have tiles downloaded from Mobac tool, with the source being Openstreet mapQuest.
Given that we may not have tiles for all positions at a higher zoom level, when we scroll, areas that are missing tiles result in a null grid or stretched images of lower zoom-level tiles.
How can I restrict scrolling to only a given bounding box and zoom level?
Implementing MapListener interface, I overrode the OnZoom function. Depending upon current zoomlevel and the points visible on screen, the scrollable boundingbox can be set by calling mapView.setScrollableAreaLimit.
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.
I followed the tutorial for map overlays that Google offers (http://developer.android.com/resources/tutorials/views/hello-mapview.html) and it works fine, except the image for the overlay doesn't scale when you zoom in and out. I have Maps zoomed in on a city, and I want to put markets on several of the buildings, but the overlay image doesn't scale when it zooms in. Is there a way to have the overlay image scale up and down as users zoom in and out?
I have seen the answer where they used vector circles as the points on the map. That wont work for me, because I need to use custom images as the point on my map.
If you want to see my code, I can post it, but it is the exact the same as the example, except for some variable name changes.
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
Does anyone know the scale ratio for android mapview zoom values?
For example if I wanted to overlay an image that was say 1 degree GPS map space square.. what size in pixels should that be when the zoom is at maximimum? Then what would I need to scale the image by per zoom level?
Is this published or known anywhere?
To do this you need to use the getProjection method in the MapView clas
http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html#getProjection()
but I don't believe you can scale overlays using the default methods, you may need to override or expand the drawAt method for the Overlay class.