Reputation: 34780
I've got a map inside a fragment. I'm trying to move the camera to a specific position (on global layout):
@Override
public void onGlobalLayout() {
getMapView().getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final GoogleMap googleMap) {
LocationManager.onLocation(new CoordinatesCallback() {
@Override
public void onCoordinates(double latitude, double longitude) {
LatLng target = new LatLng(latitude, longitude);
CameraPosition position = CameraPosition
.builder()
.target(target)
.zoom(10)
.build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(position);
googleMap.moveCamera(cameraUpdate);
}
});
}
});
}
getMapView()
returns my map view, the latitude/longitude are perfectly valid (typed them into maps, it's my home), tried both moveCamera
and animateCamera
, tried newLatLngZoom
method too, but no avail. All I'm getting is an empty map view:
What am I doing wrong?
UPDATE: I've got other maps in various parts of my app, and they work just fine.
Upvotes: 0
Views: 2848
Reputation: 34780
The problem had nothing to do with the camera. I was using MapView
inside a fragment, which apparently isn't supported. I've changed MapView
to MapFragment
and it worked. It's absolutely ridiculous that Google just creates the map and it stays blank silently with a logo, instead of throwing an exception in case of this unsupported scenario.
Upvotes: 5