java - How to create an AsyncTask properly -
i new java , since question belongs time sensitive project work, dont have time learn asynctasks. question is:
how construct asynctaskout of following code?
the goal draw route on map. fill arraylistwith 2 geopoints (start-location , destination of route). roadmanager supposed send waypoints server sends me route.
buildroadoverlay method draws route on map.
roadmanager roadmanager = new osrmroadmanager(this); arraylist<geopoint> waypoints = new arraylist<geopoint>(); geopoint mylocation = new geopoint(51.488978, 6.746994); waypoints.add(location); waypoints.add(mylocation); road road = roadmanager.getroad(waypoints); i guess has go in onpostexecute -method, right?:
polyline roadoverlay = roadmanager.buildroadoverlay(road); map.getoverlays().add(roadoverlay); the variable location upper code originates different method, intend start async task. meaning, need transmit variable asynctask when calling it, not sure how exactly.
this initialization of variable location:
geopoint location = new geopoint(double.parsedouble(place.getlongitude()), double.parsedouble(place.getlatitude()));
put time consuming task in doinbackground(), udpate view in onpostexecute().
public void drawrouteasync() { geopoint location = new geopoint(double.parsedouble(place.getlongitude()), double.parsedouble(place.getlatitude())); geopoint mylocation = new geopoint(51.488978, 6.746994); new routeasynctask().execute(location, mylocation); } private class routeasynctask extends asynctask<geopoint, void, road> { @override protected road doinbackground(geopoint... params) { arraylist<geopoint> waypoints = new arraylist<geopoint>(); waypoints.add(params[0]); // location waypoints.add(params[1]); // mylocation roadmanager roadmanager = new osrmroadmanager(mcontext); // context road road = roadmanager.getroad(waypoints); // time consuming return road; } @override protected void onpostexecute(road road) { polyline roadoverlay = roadmanager.buildroadoverlay(road); map.getoverlays().add(roadoverlay); // update view } }
Comments
Post a Comment