使用带有distancematrix和谷歌地图的AsyncTask阻止我的用户界面 [英] My UI is blocked using AsyncTask with distancematrix and google Maps

查看:189
本文介绍了使用带有distancematrix和谷歌地图的AsyncTask阻止我的用户界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google地图来显示一些标记。标记从数据库中下载,同时,我从google api获取distancematrix,在用户的当前位置和从数据库中获得的标记之间。



我的问题是,我正在用.get来做这件事,把我的用户界面(我读过.get)阻止了用户界面:

  dataFromAsyncTask = testAsyncTask.get(); 

现在,我试着去做同样没有阻塞ui,但我无法同时或以一种好的方式获得这个标记的距离。



我欣赏



这是我的旧代码和错误的.get:

  for(City city:listCity.getData()){
geoPoint = city.getLocation();
nameBeach = city.getName();

if(geoPoint == null){

} else {
latitude = String.valueOf(geoPoint.getLatitude());
longitude = String.valueOf(geoPoi nt.getLongitude());

startRetrievenDistanceAndDuration();

尝试{
dataFromAsyncTask = testAsyncTask.get();
} catch(InterruptedException i){

} catch(ExecutionException e){
}

mMap.addMarker(new MarkerOptions()。position new LatLng(geoPoint.getLatitude(),geoPoint.getLongitude()))
.title(nameCity)
.snippet(dataFromAsyncTask)
.icon(BitmapDescriptorFactory.defaultMarker()));




$ b

startRetrievenDistanceAndDuration方法:

  private void startRetrievenDistanceAndDuration(){
final String url;

testAsyncTask = new DistanceBetweenLocations(new FragmentCallback(){
$ b $ @Override
public void onTaskDone(String result){

}
});
url =https://maps.googleapis.com/maps/api/distancematrix/json?origins=+ currentLatitude +,+ currentlongitude +&; destinations =+ latitude +,+ longitude +& key = xxx;
testAsyncTask.execute(new String [] {url});
}
public interface FragmentCallback {
public void onTaskDone(String result);

AsyncTask类:

  @Override 
protected String doInBackground(String ... params){
HttpURLConnection urlConnection = null;
URL url = null;
StringBuilder result = null;
String duration =;
String distance =;

尝试{
url = new URL(params [0]);
catch(MalformedURLException m){

}
try {
urlConnection =(HttpURLConnection)url.openConnection();
} catch(IOException e){}

try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
result = new StringBuilder();
字符串行; ((line = reader.readLine())!= null){
result.append(line);
while
}
} catch(IOException e){

} finally {
urlConnection.disconnect();
}

尝试{
JSONObject jsonObject = new JSONObject(result.toString());
JSONArray jsonArray = jsonObject.getJSONArray(rows);
JSONObject object_rows = jsonArray.getJSONObject(0);
JSONArray jsonArrayElements = object_rows.getJSONArray(elements);
JSONObject object_elements = jsonArrayElements.getJSONObject(0);
JSONObject object_duration = object_elements.getJSONObject(duration);
JSONObject object_distance = object_elements.getJSONObject(distance);

duration = object_duration.getString(text);
distance = object_distance.getString(text);

} catch(JSONException e){
e.printStackTrace();
}

返回距离+,+持续时间;


$ b @Override
保护无效onPostExecute(字符串结果){
mFragmentCallback.onTaskDone(result);
}
}

我正在尝试这样做,但我只显示我列表中的最后一个标记:



调用循环方法:

  startRetrievenDistanceAndDuration(); 

然后在onTaskDone尝试放置标记,但只获取列表中的最后一个标记

  @Override 
public void onTaskDone(String result){
mMap.addMarker(new MarkerOptions()。position new LatLng(geoPoint.getLatitude(),geoPoint.getLongitude()))
.title(nameBeach)
.snippet(result)
.icon(BitmapDescriptorFactory.defaultMarker()));

$ b

更改后更新:(仍然不工作)
我可以解析Asynctask中的数据并将它发送到onPostExecute,但我只能得到一个值,而不是我所拥有的9个值....



主要活动:

  DistanceBetweenLocations task = new DistanceBetweenLocations(mlatituDouble,mlongitudeDouble){
@覆写
protected void onPostExecute(HashMap< String,String>结果){
super.onPostExecute(result);

String name = result.get(beachName);
String distance = result.get(distance);
String duration = result.get(duration);
String latitue = result.get(latitude);
String longitude = result.get(longitude);

Double mlatituDouble = Double.parseDouble(latitue);
Double doubleongitudeDouble = Double.parseDouble(longitude);

$ b $ if(mMap == null){

mMap =((SupportMapFragment)getFragmentManager()。findFragmentById(R.id.mapView))
.getMap();

Toast.makeText(getActivity(),mMap NO null,Toast.LENGTH_SHORT).show();
mMap.addMarker(new MarkerOptions()。position(new LatLng(mlatituDouble,mlongitudeDouble))
.title(name)
.snippet(distance ++ duration)
.icon(BitmapDescriptorFactory.defaultMarker()));
}
}
};

task.execute();

ASYNCTASK CLASS:。

  public class DistanceBetweenLocations extends AsyncTask< String,String,HashMap< String,String>> {

Double currentLatitude;
Double currentlongitude;
公共海滩地图beachMap;
public BackendlessCollection< Beach> dataBeach;
public GoogleMap mMap;
字符串纬度;
字符串经度;
HashMap< String,String>地图;

public DistanceBetweenLocations(Double currentLatitude,Double currentlongitude){
this.currentLatitude = currentLatitude;
this.currentlongitude = currentlongitude;
}

@Override
保护HashMap< String,String> doInBackground(String ... params){

dataBeach = beachMap.listBeach;

(海滩城市:dataBeach.getData()){
GeoPoint geoPoint = city.getLocation();
String nameBeach = city.getName();

if(geoPoint == null){

} else {
latitude = String.valueOf(geoPoint.getLatitude());
longitude = String.valueOf(geoPoint.getLongitude());

HttpURLConnection urlConnection = null;
URL url = null;
StringBuilder result = null;
String duration =;
String distance =;

尝试{
url =新网址(https://maps.googleapis.com/maps/api/distancematrix/json?origins=+ currentLatitude +,+ currentlongitude + & destinations =+ latitude +,+ longitude +& key = xxxx);
catch(MalformedURLException m){

}
try {
urlConnection =(HttpURLConnection)url.openConnection();
} catch(IOException e){
}

try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
result = new StringBuilder();
字符串行; ((line = reader.readLine())!= null){
result.append(line);
while
}
} catch(IOException e){

} finally {
urlConnection.disconnect();
}

尝试{
JSONObject jsonObject = new JSONObject(result.toString());
JSONArray jsonArray = jsonObject.getJSONArray(rows);
JSONObject object_rows = jsonArray.getJSONObject(0);
JSONArray jsonArrayElements = object_rows.getJSONArray(elements);
JSONObject object_elements = jsonArrayElements.getJSONObject(0);
JSONObject object_duration = object_elements.getJSONObject(duration);
JSONObject object_distance = object_elements.getJSONObject(distance);

duration = object_duration.getString(text);
distance = object_distance.getString(text);


map = new HashMap< String,String>();
map.put(beachName,nameBeach);
map.put(distance,distance);
map.put(duration,duration);
map.put(纬度,纬度);
map.put(longitude,longitude);


} catch(JSONException e){
e.printStackTrace();
}
}
}
返回地图;
}

}


解决方案

我会使用您的最后一段代码(UPDATED after CHANGES),好吗? 如果我弄清楚了, DistanceBetweenLocations 结果将成为海滩地理位置数据列表。因此,在 doInBackground 的for循环的每一次迭代中,您将替换map变量的值,这是您的问题。



为了解决您的问题,您可以使用 HashMap 列表或 Pojo 列表

  public class BeachPojo {
private String beachName;
私人字符串距离;
私人字符串持续时间;
私人字符串纬度;
私人字符串经度;

public String getBeachName(){
return beachName;
}

public void setBeachName(String beachName){
this.beachName = beachName;
}

public String getDistance(){
return distance;
}

public void setDistance(String distance){
this.distance = distance;
}

public String getDuration(){
return duration;
}

public void setDuration(String duration){
this.duration = duration;
}

public String getLatitude(){
return latitude;
}

public void setLatitude(String latitude){
this.latitude = latitude;
}

public String getLongitude(){
return longitude;
}

public void setLongitude(String longitude){
this.longitude = longitude;


使用 Pojo ,您的AsyncTask将如下所示:

  public class DistanceBetweenLocations extends AsyncTask< String,String,List< BeachPojo>> {

Double currentLatitude;
Double currentlongitude;
公共海滩地图beachMap;
public BackendlessCollection< Beach> dataBeach;
public GoogleMap mMap;
字符串纬度;
字符串经度;


public DistanceBetweenLocations(Double currentLatitude,Double currentlongitude){
this.currentLatitude = currentLatitude;
this.currentlongitude = currentlongitude;
}

@Override
protected List< BeachPojo> doInBackground(String ... params){
List< BeachPojo> list = new ArrayList< BeachPojo>();
BeachPojo pojo;

dataBeach = beachMap.listBeach;

(海滩城市:dataBeach.getData()){
GeoPoint geoPoint = city.getLocation();
String nameBeach = city.getName();

if(geoPoint == null){
} else {
latitude = String.valueOf(geoPoint.getLatitude());
longitude = String.valueOf(geoPoint.getLongitude());

HttpURLConnection urlConnection = null;
URL url = null;
StringBuilder result = null;
String duration =;
String distance =;

尝试{
url =新网址(https://maps.googleapis.com/maps/api/distancematrix/json?origins=+ currentLatitude +,+ currentlongitude + & destinations =+ latitude +,+ longitude +& key = xxxx);
} catch(MalformedURLException m){

}

try {
urlConnection =(HttpURLConnection)url.openConnection();
} catch(IOException e){
}

try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
result = new StringBuilder();
字符串行; ((line = reader.readLine())!= null){
result.append(line);
while
}
} catch(IOException e){

} finally {
urlConnection.disconnect();
}

尝试{
JSONObject jsonObject = new JSONObject(result.toString());
JSONArray jsonArray = jsonObject.getJSONArray(rows);
JSONObject object_rows = jsonArray.getJSONObject(0);
JSONArray jsonArrayElements = object_rows.getJSONArray(elements);
JSONObject object_elements = jsonArrayElements.getJSONObject(0);
JSONObject object_duration = object_elements.getJSONObject(duration);
JSONObject object_distance = object_elements.getJSONObject(distance);

duration = object_duration.getString(text);
distance = object_distance.getString(text);

pojo = new BeachPojo();
pojo.setBeachName(nameBeach);
pojo.setDistance(distance);
pojo.setDuration(duration);
pojo.setLatitude(latitude);
pojo.setLongitude(longitude);

list.add(pojo);

} catch(JSONException e){
e.printStackTrace();
}
}
}
返回列表;


$ / code $ / pre

现在你有一个List来迭代。我为此目标调整了代码:

  DistanceBetweenLocations任务=新的DistanceBetweenLocations(mlatituDouble,mlongitudeDouble){
@Override
protected void onPostExecute(List< BeachPojo> result){
super.onPostExecute(result);

if(mMap == null){
mMap =((SupportMapFragment)getFragmentManager()。findFragmentById(R.id.mapView))
.getMap();
}

Double beachLatitude;
Double beachLongitude;

(BeachPojo pojo:result){
beachLatitude = Double.parseDouble(pojo.getLatitude());
beachLongitude = Double.parseDouble(pojo.getLongitude());

mMap.addMarker(new MarkerOptions()。position(new LatLng(beachLatitude,beachLongitude))
.title(pojo.getBeachName())
.snippet(pojo.getDistance ()++ pojo.getDuration())
.icon(BitmapDescriptorFactory.defaultMarker()));
}
}
};

task.execute();

我希望您能理解从AsyncTask返回一个List并循环遍历 onPostExecute 方法。



注意:这是一个不知道真实代码的实现,那么您应该适应您的实际。

I'm using google maps to show some markers. The markers are download from a database and, at the same time, I get the distancematrix from google api, between the current position of the user and the marker that I get from the database.

My problem is that I was doing this with .get, bloking my ui (I've read that .get blocked the ui:

dataFromAsyncTask = testAsyncTask.get();

Now, I'm trying to do the same without blocking the ui, but I'm not be able to get at the same time, or in a good way, the distance for this markers.

I appreciate some help, please.

This is my code with my old and wrong .get:

 for (City city : listCity.getData()) {
        geoPoint = city.getLocation();
    nameBeach = city.getName();

    if (geoPoint == null) {

    } else {
        latitude = String.valueOf(geoPoint.getLatitude());
        longitude = String.valueOf(geoPoint.getLongitude());

        startRetrievenDistanceAndDuration();

        try {
            dataFromAsyncTask = testAsyncTask.get();
        } catch (InterruptedException i) {

        } catch (ExecutionException e) {
        }

        mMap.addMarker(new MarkerOptions().position(new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude()))
                .title(nameCity)
                .snippet(dataFromAsyncTask)
                .icon(BitmapDescriptorFactory.defaultMarker()));
    }
}

startRetrievenDistanceAndDuration method:

private void startRetrievenDistanceAndDuration() {
final String url;

testAsyncTask = new DistanceBetweenLocations(new FragmentCallback() {

    @Override
    public void onTaskDone(String result) {

    }
});
url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + currentLatitude + "," + currentlongitude + "&destinations=" + latitude + "," + longitude + "&key=xxx";
testAsyncTask.execute(new String[]{url});
}
public interface FragmentCallback {
    public void onTaskDone(String result);

AsyncTask class:

        @Override
        protected String doInBackground(String... params) {
            HttpURLConnection urlConnection = null;
            URL url = null;
            StringBuilder result = null;
            String duration = "";
            String distance = "";

            try {
                url=new URL(params[0]);
            }catch (MalformedURLException m){

            }
            try {
                urlConnection = (HttpURLConnection) url.openConnection();
            }catch (IOException e){}

            try {
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                result = new StringBuilder();
                String line;
                while((line = reader.readLine()) != null) {
                    result.append(line);
                }
            }catch (IOException e){

            } finally {
                urlConnection.disconnect();
            }

            try {
                JSONObject jsonObject = new JSONObject(result.toString());
                JSONArray jsonArray = jsonObject.getJSONArray("rows");
                JSONObject object_rows = jsonArray.getJSONObject(0);
                JSONArray jsonArrayElements = object_rows.getJSONArray("elements");
                JSONObject  object_elements = jsonArrayElements.getJSONObject(0);
                JSONObject object_duration = object_elements.getJSONObject("duration");
                JSONObject object_distance = object_elements.getJSONObject("distance");

                duration = object_duration.getString("text");
                distance = object_distance.getString("text");

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return distance + ", " + duration;

        }

        @Override
        protected void onPostExecute(String result) {
            mFragmentCallback.onTaskDone(result);
        }
}

I'm trying to do this, but I only show the last marker of my list:

Call in the loop the method:

startRetrievenDistanceAndDuration();

And in onTaskDone try to put the marker, but only get the last marker of my list

@Override
            public void onTaskDone(String result) {
                mMap.addMarker(new MarkerOptions().position(new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude()))
                        .title(nameBeach)
                        .snippet(result)
                        .icon(BitmapDescriptorFactory.defaultMarker()));

            }

UPDATED AFTER CHANGES: (still don't work) I can parse the data in Asynctask and send it in onPostExecute, but I only get one value, and not the 9 values that I have....

MAIN ACTIVITY:

DistanceBetweenLocations task = new DistanceBetweenLocations(mlatituDouble, mlongitudeDouble){
                    @Override
                    protected void onPostExecute(HashMap<String, String> result) {
                        super.onPostExecute(result);

                        String name = result.get("beachName");
                        String distance = result.get("distance");
                        String duration = result.get("duration");
                        String latitue = result.get("latitude");
                        String longitude = result.get("longitude");

                        Double mlatituDouble = Double.parseDouble(latitue);
                        Double mlongitudeDouble = Double.parseDouble(longitude);


                        if (mMap == null) {

                            mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView))
                                    .getMap();

                                Toast.makeText(getActivity(), "mMap NO null", Toast.LENGTH_SHORT).show();
                                mMap.addMarker(new MarkerOptions().position(new LatLng(mlatituDouble, mlongitudeDouble))
                                        .title(name)
                                        .snippet(distance + " " + duration)
                                        .icon(BitmapDescriptorFactory.defaultMarker()));
                        }
                    }
                };

                task.execute();

ASYNCTASK CLASS:.

public class DistanceBetweenLocations extends AsyncTask<String, String, HashMap<String, String>> {

    Double currentLatitude;
    Double currentlongitude;
    public BeachMap beachMap;
    public BackendlessCollection<Beach> dataBeach;
    public GoogleMap mMap;
    String latitude;
    String longitude;
    HashMap<String, String> map;

    public DistanceBetweenLocations(Double currentLatitude, Double currentlongitude){
        this.currentLatitude = currentLatitude;
        this.currentlongitude = currentlongitude;
    }

    @Override
    protected HashMap<String, String> doInBackground(String... params) {

        dataBeach = beachMap.listBeach;

        for (Beach city : dataBeach.getData()) {
            GeoPoint geoPoint = city.getLocation();
            String nameBeach = city.getName();

            if (geoPoint == null) {

            } else {
                latitude = String.valueOf(geoPoint.getLatitude());
                longitude = String.valueOf(geoPoint.getLongitude());

                HttpURLConnection urlConnection = null;
                URL url = null;
                StringBuilder result = null;
                String duration = "";
                String distance = "";

                try {
                    url = new URL("https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + currentLatitude + "," + currentlongitude + "&destinations=" + latitude + "," + longitude + "&key=xxxx");
                } catch (MalformedURLException m) {

                }
                try {
                    urlConnection = (HttpURLConnection) url.openConnection();
                } catch (IOException e) {
                }

                try {
                    InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                    result = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }
                } catch (IOException e) {

                } finally {
                    urlConnection.disconnect();
                }

                try {
                    JSONObject jsonObject = new JSONObject(result.toString());
                    JSONArray jsonArray = jsonObject.getJSONArray("rows");
                    JSONObject object_rows = jsonArray.getJSONObject(0);
                    JSONArray jsonArrayElements = object_rows.getJSONArray("elements");
                    JSONObject object_elements = jsonArrayElements.getJSONObject(0);
                    JSONObject object_duration = object_elements.getJSONObject("duration");
                    JSONObject object_distance = object_elements.getJSONObject("distance");

                    duration = object_duration.getString("text");
                    distance = object_distance.getString("text");


                    map = new HashMap<String, String>();
                    map.put("beachName", nameBeach);
                    map.put("distance", distance);
                    map.put("duration", duration);
                    map.put("latitude", latitude);
                    map.put("longitude", longitude);


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return map;
    }

}

解决方案

I'll use your last code (the "UPDATED AFTER CHANGES"), ok?

If I get it right, your DistanceBetweenLocations result will be a list of beaches geolocation data. So, on every iteration of the for loop in doInBackground, you are replacing the value of "map" variable, this is your problem.

To solve your problem, you can have a List of HashMap or a List of a Pojo like this:

public class BeachPojo {
    private String beachName;
    private String distance;
    private String duration;
    private String latitude;
    private String longitude;

    public String getBeachName() {
        return beachName;
    }

    public void setBeachName(String beachName) {
        this.beachName = beachName;
    }

    public String getDistance() {
        return distance;
    }

    public void setDistance(String distance) {
        this.distance = distance;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }
}

Using the Pojo, your AsyncTask will be like this:

public class DistanceBetweenLocations extends AsyncTask<String, String, List<BeachPojo>> {

    Double currentLatitude;
    Double currentlongitude;
    public BeachMap beachMap;
    public BackendlessCollection<Beach> dataBeach;
    public GoogleMap mMap;
    String latitude;
    String longitude;


    public DistanceBetweenLocations(Double currentLatitude, Double currentlongitude){
        this.currentLatitude = currentLatitude;
        this.currentlongitude = currentlongitude;
    }

    @Override
    protected List<BeachPojo> doInBackground(String... params) {
        List<BeachPojo> list = new ArrayList<BeachPojo>();
        BeachPojo pojo;

        dataBeach = beachMap.listBeach;

        for (Beach city : dataBeach.getData()) {
            GeoPoint geoPoint = city.getLocation();
            String nameBeach = city.getName();

            if (geoPoint == null) {
            } else {
                latitude = String.valueOf(geoPoint.getLatitude());
                longitude = String.valueOf(geoPoint.getLongitude());

                HttpURLConnection urlConnection = null;
                URL url = null;
                StringBuilder result = null;
                String duration = "";
                String distance = "";

                try {
                    url = new URL("https://maps.googleapis.com/maps/api/distancematrix/json?origins=" + currentLatitude + "," + currentlongitude + "&destinations=" + latitude + "," + longitude + "&key=xxxx");
                } catch (MalformedURLException m) {

                }

                try {
                    urlConnection = (HttpURLConnection) url.openConnection();
                } catch (IOException e) {
                }

                try {
                    InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                    result = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }
                } catch (IOException e) {

                } finally {
                    urlConnection.disconnect();
                }

                try {
                    JSONObject jsonObject = new JSONObject(result.toString());
                    JSONArray jsonArray = jsonObject.getJSONArray("rows");
                    JSONObject object_rows = jsonArray.getJSONObject(0);
                    JSONArray jsonArrayElements = object_rows.getJSONArray("elements");
                    JSONObject object_elements = jsonArrayElements.getJSONObject(0);
                    JSONObject object_duration = object_elements.getJSONObject("duration");
                    JSONObject object_distance = object_elements.getJSONObject("distance");

                    duration = object_duration.getString("text");
                    distance = object_distance.getString("text");

                    pojo = new BeachPojo();
                    pojo.setBeachName(nameBeach);
                    pojo.setDistance(distance);
                    pojo.setDuration(duration);
                    pojo.setLatitude(latitude);
                    pojo.setLongitude(longitude);

                    list.add(pojo);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return list;
    }
}

Now you have a List to iterate. I have adjusted the code a little bit to this goal:

DistanceBetweenLocations task = new DistanceBetweenLocations(mlatituDouble, mlongitudeDouble){
    @Override
    protected void onPostExecute(List<BeachPojo> result) {
        super.onPostExecute(result);

        if (mMap == null) {
            mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapView))
                    .getMap();
        }

        Double beachLatitude;
        Double beachLongitude;

        for (BeachPojo pojo : result) {
            beachLatitude = Double.parseDouble(pojo.getLatitude());
            beachLongitude = Double.parseDouble(pojo.getLongitude());

            mMap.addMarker(new MarkerOptions().position(new LatLng(beachLatitude, beachLongitude))
                .title(pojo.getBeachName())
                .snippet(pojo.getDistance() + " " + pojo.getDuration())
                .icon(BitmapDescriptorFactory.defaultMarker()));
        }
    }
};

task.execute();

I hope you understand the idea of returning a List from your AsyncTask and loop throught the result on onPostExecute method.

Note: this is an implementation without knowing the real code, then you should adjust to your reality.

这篇关于使用带有distancematrix和谷歌地图的AsyncTask阻止我的用户界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆