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 callgetmap()after inflation complete, ordelay
getmap()call later point, orsubclass
mapfragment, callgetmap(), add marker in methodonactivitycreated()(basically, called afteroncreateview()has completed)
Comments
Post a Comment