I'm trying to achieve that camera update would center between two positions
BUT if resulting zoom level is bigger than 12 it should be set to 12.
So i need some:
CameraUpdateFactory.newLatLngBounds(bounds,padding);
But instead of padding there should be max zoom level.
My solution requires that i calculate exact screen bounds that will be after camera update and here i got stuck.
If you need to calculate map screen bounds, you should use VisibleRegion
VisibleRegion visibleRegion = googleMap.getProjection().getVisibleRegion();
read also this question, may be similar to what you need.
Related
I'm working on an application that uses Google Maps API.
My map is displayed with a defined bearing and rotation/compass are disabled.
I'd like to add Camera Bounds to my map so that the user does not leave the area of interest.
However the API seems to provide only one method for that, which is
GoogleMap.setLatLngBoundsForCameraTarget(LatLngBounds)
The issue is that LatLngBounds are "boxes" aligned with latitude and longitude.
So on my map that has a bearing, the camera bounds have a diamond shape instead of a square one, which is a bit weird.
Is there a way I can set some Camera Bounds that are not Latitude/Longitude aligned ?
I thought of writing a workaround with a CameraMoveListener that would trigger a CameraUpdate, but it's a bit of work for a result that I believe would be not that great in term of user experience.
I am working with Google API and I want to show view of any location on Google map from particular height. I don't want to assign zoom level directly. I want to calculate it dynamically with respect to height (Eg. 1Km, 2Km, 3Km, etc.). If any one have idea please let me know.
Thanks in advance.
Try using map.setZoom(your value)
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
map.setCenter(pt);
map.setZoom(your desired zoom);
}
Referred: https://developers.google.com/maps/documentation/javascript/reference#Map
You won't find a direct, out-of-the-box solution for your problem because it depends on the size of the device and the distance from which you look at it.
For example, if you are holding you device at 40 centimeters from your eyes, and then you move it to 50 centimeters, the perceived distance to the ground will change a lot.
Anyway, you can estimate the distance using a formula to Calculate distance knowing actual and perceived size.
Using this formula you can calculate the perceived distance for each zoom level based on the perceived size of an object with a known size (a car or a building for example), the size of your device and the distance from which you're looking at it, and then find a relation to know what zoom level you need to apply to simulate a given altitude.
Take into account that this will always be an approximation because you can't be sure about the distance from which your users are looking at your map, and also because the map represents the earth in a plane, so the farther the zoom, the worse this method will be.
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 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.
For some reason this seems much harder to find than I thought it would be. I am working with a map display and I have set the zoom level to 15:
mapController.setZoom(15);
What are the different zoom levels equal to in distance? I am assuming is some kind of log or exponential scale. If I choose 1 or 18 for the zoom levels, what is the approximate distance that will be displayed on the screen for each zoom level on a map?
According to MapController.setZoom:
Sets the zoomlevel of the map. The value will be clamped to be between
1 and 21 inclusive, though not all areas have tiles at higher zoom
levels. This just sets the level of the zoom directly; for a
step-by-step zoom with fancy interstitial animations, use zoomIn() or
zoomOut().
Parameters: zoomLevel - At zoomLevel 1, the equator of the earth is
256 pixels long. Each successive zoom level is magnified by a factor
of 2.
Returns: the new zoom level, between 1 and 21 inclusive.
See the entry in the OpenStreetMap FAQ (OSM uses the same tiling system as Google).
If you are looking to zoom to include certain places take a look at zoomToSpan. That might help some of your issues. I used it to zoom in on a group of points, and just calculated the min/max points and was good to go.