The way I got mine resolved, I had to do this:
final MapView mapView = (MapView)fragmentView.findViewById(R.id.map_fieldLocation);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng coordinates = new LatLng(match.match.LocationLatitude, match.match.LocationLongitude);
googleMap.addMarker(new MarkerOptions().position(coordinates).title(match.match.LocationAddress));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 15));
mapView.onResume();
}
});
The important part that I was missing is that you have to call the onCreate()
method before you call getMapAsync()
and once the callback is called, you need to call onResume()
on the MapView
object.
That totally solved it for me.
Here's what it would look like in your own class:
public class MainActivity extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (getView() != null) {
final MapView mapView = (MapView)getView().findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng coordinates = new LatLng(match.match.LocationLatitude, match.match.LocationLongitude);
googleMap.addMarker(new MarkerOptions().position(coordinates).title(match.match.LocationAddress));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 15));
mapView.onResume();
}
}
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
Hope this helps!