KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've got a UI that has a MapFragment with a transparent View overlaid on top of it. The map takes up the entire screen, whereas the View is just the left third of the screen. As a result, the default "center" of the map is off. When someone clicks on a marker, I want to center that marker in the wholly visible area of the MapFragment (not the center of the MapFragment itself). Since this is hard to describe with words, let me use a few pictures. Suppose this is how my UI looks: When the user clicks a marker, I want to both center it and zoom in to see it closer. Without any adjustments, this is what you'll get: What I want is for the marker to be centered, but in the space to the right, like this: It's very easy to achieve this feat if you're not changing the zoom level using the map's projection: // Offset the target latitude/longitude by preset x/y ints LatLng target = new LatLng(latitude, longitude); Projection projection = getMap().getProjection(); Point screenLocation = projection.toScreenLocation(target); screenLocation.x += offsetX; screenLocation.y += offsetY; LatLng offsetTarget = projection.fromScreenLocation(screenLocation); // Animate to the calculated lat/lng getMap().animateCamera(CameraUpdateFactory.newLatLng(offsetTarget)); However, if you're changing the zoom level at the same time, the above calculations don't work (since the lat/lng offsets change at different zoom levels). Let me run down a list of attempted fixes: Changing the zoom level quickly, doing the calculations, zooming back to the original camera position, then animating. Unfortunately the sudden camera change (even if it's o
Tags (comma-separated)
Save Edits
Cancel