java - Adding Marker to map api v2 in AsyncTask -


edit!

not sure thinking, can't update ui in background thread. oops.

how pass marker add ui?

edit!

i'm trying add markers map api v2. if add markers in oncreate work fine. if add markers in endpointstask directly below address information , convert lat long values not add marker points.

here code add marker:

mmap.addmarker(new markeroptions()     .position(new latlng(lati, longi))     .title("hello world"));  

works fine when put in actual double values in oncreate. not work @ double values in endpointstask (see below). in case wondering sent lati longi values console , prints lat long ok.

public class finderactivity extends activity implements locationlistener  {      googlemap mmap;     location mylocation;     edittext length;     string lengthstring;     locationmanager locationmanager;     //spinner s;      list<address> address;     geocoder coder = new geocoder(this);     private static final string tag_id = "id";     private static final string tag_firstname = "namefirst";     private static final string tag_lastname = "namelast";     private static final string tag_email = "emailaddress";     private static final string tag_address = "streetaddress";     private static final string tag_state = "state";      private static final string tag_phone = "phone";     jsonarray contacts = null;      @suppresslint("newapi")     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.maps);         mmap = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)).getmap();         if (mmap!= null) {              mmap.setmaptype(googlemap.map_type_normal);               mmap.setmylocationenabled(true);             mmap.animatecamera(cameraupdatefactory.zoomby(17));              }          locationmanager locationmanager = (locationmanager) getsystemservice(location_service);         criteria cr = new criteria();         string provider = locationmanager.getbestprovider(cr, true);          location location = locationmanager.getlastknownlocation(provider);          locationmanager.requestlocationupdates(provider, 20, 0, (locationlistener) this);          mmap.movecamera(cameraupdatefactory.newlatlng((new latlng(location.getlatitude(), location.getlongitude()))));          //works here          //mmap.addmarker(new markeroptions()         //.position(new latlng(38.923546, -83.582954))         //.title("hello world"));               new endpointstask().execute(getapplicationcontext());      }      public class endpointstask extends asynctask<context, integer, long> {          public long doinbackground(context... contexts) {            contactinfoendpoint.builder endpointbuilder = new contactinfoendpoint.builder(               androidhttp.newcompatibletransport(),               new jacksonfactory(),               new httprequestinitializer() {               public void initialize(httprequest httprequest) { }               });       contactinfoendpoint endpoint = cloudendpointutils.updatebuilder(       endpointbuilder).build();        try {          string apples = endpoint.listcontactinfo().execute().tostring();          jsonobject jobject = new jsonobject(apples);          jsonarray jsonarr = jobject.getjsonarray("items");           for(int =0 ; i<jsonarr.length() ;i++ ){              jsonobject jsonobj1 = jsonarr.getjsonobject(i);                           // storing each json item in variable                         string id = jsonobj1.getstring(tag_id);                         string namefirst1 = jsonobj1.getstring(tag_firstname);                         string namelast1 = jsonobj1.getstring(tag_lastname);                         string emailaddress1 = jsonobj1.getstring(tag_email);                         string streetaddress1 = jsonobj1.getstring(tag_address);                         string phone1 = jsonobj1.getstring(tag_phone);                          //test see if made string                         log.d("your_tag", "first name: " + namefirst1 + " last name: " + namelast1);                             address = coder.getfromlocationname(streetaddress1,5);                             if (address == null) {                                 return null;                             }                             address location1 = address.get(0);                            double lati = location1.getlatitude();                             double longi = location1.getlongitude();                     log.d("location", "location:" + lati + " " +  longi);                               // doesnt work here                             mmap.addmarker(new markeroptions()                              .position(new latlng(lati, longi))                              .title("hello world"));               }          } catch (ioexception e) {         e.printstacktrace();       } catch (jsonexception e) {         // todo auto-generated catch block         e.printstacktrace();     }           return (long) 0; } 

there several ways postexecute method can solve problem this: how pass result of asynctask onpostexecute method parent activity android

protected void onpostexecute(long result) {     // can call method of activity     // example can generate list of      // markers , passed param of method      // activity.  } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -