in project i'm loading maps programmatically on fragment. however, adding markers on map not working. no error shown marker not on map well.
i'm following specification have no idea why not working. (lat , lng of marker , camera same)
my fragment code
public class mainmapfragment extends fragment implements onmapreadycallback { supportmapfragment mmapfragment; static final latlng library = new latlng(lat, lng); @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { super.oncreate(savedinstancestate); return inflater.inflate(r.layout.main_map_layout,container,false); } @override public void onviewcreated(view view, bundle savedinstancestate) { //set initial stage of map //it set on code (not on xml) because map created programmatically googlemapoptions options = new googlemapoptions(); cameraposition ufv_position = new cameraposition.builder() .target(new latlng(lat,lng)) .zoom(15) .tilt(0) .bearing(40) .build(); options.maptype(googlemap.map_type_normal) .compassenabled(false) .rotategesturesenabled(false) .tiltgesturesenabled(false) .camera(ufv_position); //load map given options mmapfragment = supportmapfragment.newinstance(options); fragmenttransaction fragmenttransaction = getchildfragmentmanager().begintransaction(); fragmenttransaction.add(r.id.map, mmapfragment); fragmenttransaction.commit(); } @override public void onmapready(googlemap googlemap) { googlemap.addmarker(new markeroptions() .position(library) .title("library") .icon(bitmapdescriptorfactory.fromresource(r.drawable.book))); }
}
add mmapfragment.getmapasync(this);
onmapready method gets called
Comments
Post a Comment