java - How to show specific markers in Android Maps activity? -


i trying create android app displays map shows every university | school in area/nearby. i've looked on , google , have found tutorials on how add markers, add tiles, or show specific lat/lng there way show specific markers based on specific parameters? example, if want show every marker universities/schools how go passing parameters mapfragment? haven't tried because haven't found hints @ how except reference web app api didn't android specific api.

hope helps travel guide app code

    public class searchplacetype extends activity {     string[] itemtypename ={             "airport",             "atm",             "bank",             "bus_station",             "gas_station",             "hospital",             "mosque",             "park",             "restaurant",             "university",             "food"          };      listview listview;     @override     protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);          setcontentview(r.layout.search_place_type);          listview = (listview)findviewbyid(r.id.typelist);          listview.setadapter(new placetypeadapter(searchplacetype.this, itemtypename));          listview.setonitemclicklistener(new onitemclicklistener()          {             @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id)              {                 intent intent = new intent(searchplacetype.this,nearbyplaces.class);                  intent.putextra("positionoftype", (int)position);                  startactivity(intent);             }         });     }  } 

than class tell near places

public class nearbyplaces extends activity {     arraylist<hashmap<string, string>> list = new arraylist<hashmap<string, string>>();      listview listview;      int positionoftype = 0;      context context;      mylocation mylocation;      double current_location_lat, current_location_lng;      public static string latstr = "";     public static string longstr = "";      public static latlng mylatlng = null;      public static latlng destinationlatlng = null;      @override     protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);          setcontentview(r.layout.near_by_places);          context = nearbyplaces.this;          bundle extras = getintent().getextras();          if(extras!=null)         {             positionoftype = extras.getint("positionoftype", positionoftype);         }          listview = (listview)findviewbyid(r.id.nearbylist);          mylocation = new mylocation(context);          if (mylocation.islocationavailable() && mylocation.getuserlocation() != null)         {             current_location_lat =  mylocation.getuserlocation().latitude;              current_location_lng =  mylocation.getuserlocation().longitude;              latstr = current_location_lat + "";              longstr = current_location_lng + "";              mylatlng = new latlng(current_location_lat, current_location_lng);              //url = url_part1 + latstr + "," + longstr + url_part2;              log.d("latitude", string.valueof(current_location_lat));              log.d("longitude", string.valueof(current_location_lng));               new placetask(context, positionoftype, latstr, longstr, new ontaskdonelistener()              {                 @override                 public void ontaskdone(jsonobject jsonobject)                  {                     if(jsonobject!=null)                     {                         try                          {                             jsonobject obj = jsonobject;//new jsonobject(jsonobject);                              string status = obj.getstring("status");                              if(status.equals("ok"))                             {                                 jsonarray arr = obj.getjsonarray("results");                                  for(int = 0; < arr.length(); i++)                                 {                                     double lat = arr.getjsonobject(i).getjsonobject("geometry").getjsonobject("location").getdouble("lat");                                      double lng = arr.getjsonobject(i).getjsonobject("geometry").getjsonobject("location").getdouble("lng");                                       string place_name = arr.getjsonobject(i).getstring("name");                                      string vicinity = arr.getjsonobject(i).getstring("vicinity");                                      hashmap<string, string> map = new hashmap<string,string>();                                      map.put("placename", place_name);                                      map.put("vicinity", vicinity);                                      map.put("lat", string.valueof(lat));                                      map.put("lng", string.valueof(lng));                                      list.add(map);                                 }                                  nearbyplaceadapter adapter = new nearbyplaceadapter(context, list);                                  listview.setadapter(adapter);                             }                         }                          catch (jsonexception e)                          {                             e.printstacktrace();                         }                     }                     else                     {                         toast.maketext(context, "response null", toast.length_long).show();                     }                  }             }).execute();              //showsearchdialog(map);             }                        else         {             toast.maketext(context, "please enable location services , gps device",                      toast.length_long).show();         }                 listview.setonitemclicklistener(new onitemclicklistener()          {             @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id)              {                 hashmap<string, string> map = list.get(position);                  intent intent = new intent(context,directionactivity3.class);                  destinationlatlng = new latlng(double.valueof(map.get("lat")), double.valueof(map.get("lat")));                  startactivity(intent);             }         });     }  } 

draw marker using mapypane class

public class mapypane extends activity implements onmapreadycallback  {     string[] itemtypename ={             "airport",             "atm",             "bank",             "bus_station",             "gas_station",             "hospital",             "mosque",             "park",             "restaurant",             "university",             "food"          };      marker mymarker;      gmapv2direction md;      mylocation mylocation;      googlemap googlemap;      double current_location_lat, current_location_lng;      public static string latstr = "";     public static string longstr = "";      dialog searchdialog;      imageview searchdialogiv;     imageview searchicon;      edittext searchtext;      context context;      integer[] imageid = {             r.drawable.school_3,             r.drawable.atm_3,             r.drawable.school_3,             r.drawable.police_station_3,             r.drawable.cng_station_3,//5             r.drawable.hospital_3,             r.drawable.school_3,             r.drawable.hospital_3,//8             r.drawable.hotel_3,             r.drawable.cng_station_3,             r.drawable.hotel_3     };      int positiontofind =  0;      @override     protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);          setcontentview(r.layout.activity_main);          context = mapypane.this;          md = new gmapv2direction();           mapfragment mapfragment = (mapfragment) getfragmentmanager()                 .findfragmentbyid(r.id.fragment_map);          mapfragment.getmapasync(this);          googlemap = mapfragment.getmap();//my doctory..          bundle extras = getintent().getextras();          if(extras!=null)         {             positiontofind = extras.getint("positiontofind", positiontofind);         }             searchtext = (edittext)findviewbyid(r.id.search_text);          searchdialogiv = (imageview)findviewbyid(r.id.search_dialogiv);          searchdialogiv.setonclicklistener(new onclicklistener()         {             @override             public void onclick(view v)             {                 if(googlemap==null)                 {                     toast.maketext(context, "unable load map", toast.length_long).show();                 }                 else                 {                     showsearchdialog(googlemap);                 }             }         });          searchicon = (imageview)findviewbyid(r.id.search_icon);          searchicon.setvisibility(view.gone);          searchtext.setvisibility(view.gone);          searchicon.setonclicklistener(new onclicklistener()         {             @override             public void onclick(view v)             {                 //if(sear)                 new placetask(context, searchtext.gettext().tostring(), latstr, longstr, new ontaskdonelistener()                 {                     @override                     public void ontaskdone(jsonobject jsonobject)                     {                         //drawmarkersonmap(jsonobject, googlemap,postponeentertransition());                     }                 }).execute();             }         });     }      /*public void drawpathbetween(latlng sourceposition,latlng destposition,googlemap mmap)     {         document doc = md.getdocument(sourceposition, destposition,                 gmapv2direction.mode_driving);          arraylist<latlng> directionpoint = md.getdirection(doc);         polylineoptions rectline = new polylineoptions().width(3).color(                 color.red);          (int = 0; < directionpoint.size(); i++)          {             rectline.add(directionpoint.get(i));         }         polyline polylin = mmap.addpolyline(rectline);     }*/      @override     public void onmapready(googlemap map)      {         // check if map created or not         if (map == null)          {             toast.maketext(getapplicationcontext(),                     "sorry! unable load maps", toast.length_short)                     .show();         }         else         {                        mylocation = new mylocation(mapypane.this, map);              if (mylocation.islocationavailable() && mylocation.getuserlocation() != null)             {                 current_location_lat =  mylocation.getuserlocation().latitude;                  current_location_lng =  mylocation.getuserlocation().longitude;                  latstr = current_location_lat + "";                  longstr = current_location_lng + "";                  //url = url_part1 + latstr + "," + longstr + url_part2;                  log.d("latitude", string.valueof(current_location_lat));                  log.d("longitude", string.valueof(current_location_lng));                  // showing current location                  map.setmylocationenabled(true);                   // move camera instantly hamburg zoom of 15.                 map.movecamera(cameraupdatefactory.newlatlngzoom(new latlng(current_location_lat, current_location_lng), 15));                  // zoom in, animating camera.                 map.animatecamera(cameraupdatefactory.zoomto(10), 2000, null);                    // moving camera location animation                  /*cameraposition cameraposition = new cameraposition.builder().target(                         new latlng(current_location_lat, current_location_lng)).zoom(12).build();                  //cameraposition cameraposition = new cameraposition.builder().target(                 //new latlng( -33.8650, 151.2094)).zoom(12).build();                  map.animatecamera(cameraupdatefactory.newcameraposition(cameraposition));*/                    markeroptions markeroptions = new markeroptions().title("yourlocation").position(new latlng(current_location_lat, current_location_lng)).icon(bitmapdescriptorfactory                         .fromresource(r.drawable.gas_station));//gas_station                   mymarker = map.addmarker(markeroptions);                   new placetask(context, positiontofind, latstr, longstr, new ontaskdonelistener() {                      @override                     public void ontaskdone(jsonobject jsonobject)                      {                      }                 });                  //showsearchdialog(map);                 }                            else             {                 toast.maketext(mapypane.this, "please enable location services , gps device",                          toast.length_long).show();             }                    }         /* latlng sydney = new latlng(-33.867, 151.206);          map.setmylocationenabled(true);         map.movecamera(cameraupdatefactory.newlatlngzoom(sydney, 13));          map.addmarker(new markeroptions()                 .title("sydney")                 .snippet("the populous city in australia.")                 .position(sydney));*/           /*map.movecamera(cameraupdatefactory.newlatlngzoom(                 new latlng(41.889, -87.622), 16));          // can customize marker image using images bundled         // app, or dynamically generated bitmaps.         map.addmarker(new markeroptions()                 .icon(bitmapdescriptorfactory.fromresource(r.drawable.ic_launcher))                 .anchor(0.0f, 1.0f) // anchors marker on bottom left                 .position(new latlng(41.889, -87.622)));*/     }      private void drawmarkersonmap(jsonobject jsonobject,final googlemap googlemap,int posi)     {         if(jsonobject!=null)         {             googlemap.clear();              try              {                 jsonobject obj = jsonobject;//new jsonobject(jsonobject);                  string status = obj.getstring("status");                  if(status.equals("ok"))                 {                     jsonarray arr = obj.getjsonarray("results");                      for(int = 0; < arr.length(); i++)                     {                         double lat = arr.getjsonobject(i).getjsonobject("geometry").getjsonobject("location").getdouble("lat");                          double lng = arr.getjsonobject(i).getjsonobject("geometry").getjsonobject("location").getdouble("lng");                           string food_name = arr.getjsonobject(i).getstring("name");                          string vicinity = arr.getjsonobject(i).getstring("vicinity");                          markeroptions marker = new markeroptions().position(new latlng(lat, lng)).icon(bitmapdescriptorfactory                                 .fromresource( imageid[posi]));// r.drawable.ic_launcher));//gas_station                           marker.title(food_name);                          marker.snippet(vicinity);                          final marker testmarker = googlemap.addmarker(marker);                          googlemap.setonmarkerclicklistener(new onmarkerclicklistener()                         {                             @override                             public boolean onmarkerclick(marker markker)                             {                                 if(markker.equals(testmarker))                                 {                                     //drawpathbetween(mymarker.getposition(), markker.getposition(), googlemap);                                 }                                 else                                 {                                  }                                 return false;                             }                         });                     }                 }             }              catch (jsonexception e)              {                 e.printstacktrace();             }         }     }      private void showsearchdialog(final googlemap map)      {         searchdialog = new dialog(mapypane.this);          searchdialog.requestwindowfeature(window.feature_no_title);          searchdialog.setcontentview(r.layout.menu_item_custom_dialog);                searchdialog.setcanceledontouchoutside(false);          listview list;         final string[] web = {                 "airport",                 "atm",                 "bank",                 "bus_station",                 "gas_station",  //department_store  ya home_goods_store                 "hospital",  //health                 "mosque",//7                 "park",                 "restaurant",//instead of hotels                 "university",                 "food"         } ;         integer[] imageid = {                 r.drawable.school_3,                 r.drawable.atm_3,                 r.drawable.school_3,                 r.drawable.police_station_3,                 r.drawable.cng_station_3,//5                 r.drawable.hospital_3,                 r.drawable.school_3,                 r.drawable.hospital_3,//8                 r.drawable.hotel_3,                 r.drawable.cng_station_3,                 r.drawable.hotel_3         };          customlist adapter = new                 customlist(mapypane.this, web, imageid);          list = (listview) searchdialog.findviewbyid(r.id.list_location);         list.setadapter(adapter);          ///list.setselector(r.drawable.list_item_selector);          list.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view,                     final int position, long id) {                 //toast.maketext(mapypane.this, "you clicked @ " +web[+ position], toast.length_short).show();                  connectivitymanager connmanager = (connectivitymanager) getsystemservice(context.connectivity_service);                 networkinfo mwifi = connmanager.getnetworkinfo(connectivitymanager.type_wifi);                  if (mwifi.isconnected())                 {                     if(latstr.equals(""))                     {                         toast.maketext(mapypane.this, " please enable gps location ", toast.length_short).show();                     }                      else                     {                         new placetask(mapypane.this, position, latstr, longstr, new ontaskdonelistener()                         {                             @override                             public void ontaskdone(jsonobject jsonobject)                             {                                 drawmarkersonmap(jsonobject, map,position);                             }                         }).execute();                          searchdialog.dismiss();                     }                        }                 else                 {                     toast.maketext(mapypane.this, "internet not available", toast.length_short).show();                 }             }         });          searchdialog.show();      }  } 

Comments