android - Unable to add multiple markers in a Google Map -


i trying have simpler implementation of google map in android app. able launch google map unable show multiple markers there. if keep latitude , longitude values , name of places hardcoded things work, dynamically variables , string values unable show them. have gone through link suggested many on here. want simpler implementation of it.

below code have used in main activity:

public class map_activity_with_fragment extends appcompatactivity implements onmapreadycallback {  private googlemap googlemap; string origin, destination, start_date, num_adult, num_infant, origin_map, destination_map; context context; list<address> addr_origin, addr_dest; double latitude_origin, longitude_origin, latitude_destination, longitude_destination;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     intent intent = getintent();     bundle extras = intent.getextras();     origin = extras.getstring(mainactivity.origin);     destination = extras.getstring(mainactivity.destination);     start_date = extras.getstring(mainactivity.start_date);     num_adult = extras.getstring(mainactivity.adult);     num_infant = extras.getstring(mainactivity.infant);     origin_map = extras.getstring(mainactivity.origin_map);     destination_map = extras.getstring(mainactivity.destination_map);     context = map_activity_with_fragment.this;     settitle("location map");     setcontentview(r.layout.activity_map__with__fragment);      try     {         initializemap();      } catch (exception e) {         e.printstacktrace();     } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.activity_map__with__fragment, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); }  @override public void onmapready(googlemap googlemap) {     addmarkers(googlemap); }   @override protected void onresume() {     super.onresume();     initializemap(); }  private void initializemap() {     if (googlemap == null) {         mapfragment mapfragment = (mapfragment) getfragmentmanager().findfragmentbyid(r.id.map);         mapfragment.getmapasync(this);     } }  private void addmarkers(googlemap googlemap) {     try {         geocoder geocoder = new geocoder(context);         addr_origin = geocoder.getfromlocationname(origin_map, 1);         addr_dest = geocoder.getfromlocationname(destination_map, 1);         if (addr_origin.size() > 0) {             latitude_origin = addr_origin.get(0).getlatitude();             longitude_origin = addr_origin.get(0).getlongitude();         }         if (addr_dest.size() > 0) {             latitude_destination = addr_dest.get(0).getlatitude();             longitude_destination = addr_dest.get(0).getlongitude();         }         marker m1 = googlemap.addmarker(new markeroptions().position(new latlng(latitude_origin, longitude_origin)).title(origin_map));         marker m2 = googlemap.addmarker(new markeroptions().position(new latlng(latitude_destination, longitude_destination)).title(destination_map));     } catch (exception e) {         e.printstacktrace();     } } } 

please me out! in advance!

ok, going update own question.

i testing these code changes on device of api level 16, , hence markers , polylines not getting rendered correctly. tested same code on device of api level 19, , worked fine. did not modify part of code this. things working now. :)


Comments