I'm trying to explore using the MapView class for GoogleMap display, with no luck, as most codes examples are using MapFragment which I do not want.
I am using Google Maps Android API v2.
At first, just for testing with here from Google's example, I managed to get the typical normal map to display.
public class POnlineMapView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.online_map_activity);
}
}
The code above works perfectly which show that everything has been set up properly.
I am now trying to use the MapView class to manipulate the display settings such as the center point, but it seems like I am obtaining a null object everytime I try to obtain the GoogleMap object. Why is this so?
public class POnlineMapView extends Activity {
private MapView myMapView;
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myMapView = new MapView(getApplicationContext());
Bundle b = getIntent().getExtras();
double longitude = b.getDouble("longitude");
double latitude = b.getDouble("latitude");
setContentView(R.layout.online_map_activity);
map = myMapView.getMap();
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude,longitude));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(17);
map.moveCamera(center); //this gives a NullPointerException, probably due to the myMapView.getMap() method?
map.animateCamera(zoom);
}
}