Marks for Google Maps Android -
i have 2 maps on different tabs...i trying add location of business on map , use marker...this code need make work? not pull map anymore when put marker code have in code...please no 1 liners explain need in order fix problem thank!
import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.marker; import com.google.android.gms.maps.model.markeroptions; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmenttransaction; public class contacts2 extends fragmentactivity { private static final string contacts2 = "contacts2"; private googlemap contact2map; @override protected void oncreate(bundle arg0) { super.oncreate(arg0); setcontentview(r.layout.contacts2); addtest(); } private void addtest() { latlng position = new latlng(26.0460563,-80.2517702); contact2map.addmarker(new markeroptions() .title("text") .snippet("text") .icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_blue)) .position(position)); } @override protected void onresume() { super.onresume(); supportmapfragment mmapfragment = supportmapfragment.newinstance(); fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragmenttransaction.add(r.id.contacts2map, mmapfragment,contacts2); fragmenttransaction.commitallowingstateloss(); } @override protected void onpause() { super.onpause(); fragmentmanager fmanager = getsupportfragmentmanager(); fragment fragment = fmanager.findfragmentbytag(contacts2); fmanager.begintransaction().remove(fragment).commitallowingstateloss(); }
}
try this:
@override protected void oncreate(bundle arg0) { super.oncreate(arg0); setcontentview(r.layout.contacts2); //add line contact2map= ((supportmapfragment) getfragmentmanager().findfragmentbyid(r.id.contacts2map)) .getmap(); addtest(); }
Comments
Post a Comment