How to add properties (markers, geopoints, etc...) to a Google Android Map v2 created programmatically -


the code used this:

private googlemap mmap;  mapfragment mmapfragment = mapfragment.newinstance();  fragmenttransaction fragmenttransaction = this.getfragmentmanager().begintransaction(); fragmenttransaction.add(r.id.rl_map, mmapfragment); fragmenttransaction.commit();  mmap = mmapfragment.getmap(); 

and shows map inside relative layout (r.id.rl_map), when try put marker with:

mmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("hello world")); 

it gives null pointer exception

that because googlemap not yet exist. commit() schedules map created, not created time try calling getmap().

either:

  • switch inflating layout containing mapfragment, can call getmap() after inflation complete, or

  • delay getmap() call later point, or

  • subclass mapfragment , call getmap() , add marker in method onactivitycreated() (basically, called after oncreateview() has completed)


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -