gpt4 book ai didi

Android ItemizedOverlay 问题

转载 作者:行者123 更新时间:2023-11-29 18:16:17 27 4
gpt4 key购买 nike

我必须在特定点的 map 上放置一些叠加层,我从 API 获取点坐标。我在异步任务中进行抓取。我成功地放置了叠加层,当我放大 map 或跨越它时,响应非常慢。这是我的 overlayitem 类和我的异步任务

public class Marker extends ItemizedOverlay<OverlayItem> {
private Context con;

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();


public Marker(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}

public Marker(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
con=context;
// TODO Auto-generated constructor stub
}

@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);
}

@Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}

public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
}

...

private class TeleportdAPIParser extends AsyncTask<Void, Object, Void> {

private final HttpTransport http= AndroidHttp.newCompatibleTransport();
private HttpRequestFactory fact;
private HttpRequest request;
private HttpResponse response;
private String urlString;
private JsonFactory jsonFactory;
private JsonParser jp;
MapView mapView;
Marker marker;
List<Overlay> mapOverlays;
ImageAdapter adapter;



@Override
protected void onPreExecute() {
super.onPreExecute();
mapView=(MapView) findViewById(R.id.mapView);
Drawable drawable = getResources().getDrawable(R.drawable.puce);
marker = new Marker(drawable);
mapOverlays = mapView.getOverlays();
adapter=new ImageAdapter();
GridView gridview=(GridView) findViewById(R.id.gridView);


}


@Override
protected Void doInBackground(Void... params) {

fact=http.createRequestFactory();
jsonFactory = new JsonFactory();
TPortItem tpi= new TPortItem();
TPortItemList tpl=new TPortItemList();


urlString="http://v1.api.teleportd.com:8080/search?apikey=1c5a31ccf46c54572e484e103c97239bd&loc=%5B48.87,2.34,5.0,5.0%5D";
try {
//urlString=URLEncoder.encode(urlString,"UTF-8");
request = fact.buildGetRequest(new GenericUrl(urlString));
HttpHeaders header=new HttpHeaders();
header.setAcceptEncoding("gzip");
request.setHeaders(header);
response = request.execute();
jp = jsonFactory.createJsonParser(new BufferedInputStream(response.getContent()));


while(jp.nextValue()!=JsonToken.NOT_AVAILABLE){

jp.nextValue();
while(jp.getCurrentToken()!=JsonToken.END_OBJECT && jp.getCurrentToken()!=null){

if(jp.getCurrentName().equals("sha")){
tpi.sha=jp.getText();
}

if(jp.getCurrentName().equals("date")){
tpi.date=jp.getIntValue();
}

if(jp.getCurrentName().equals("age")){
tpi.age=jp.getIntValue();
}

if(jp.getCurrentName().equals("thumb")){
tpi.thumb=jp.getText();
if(adapter.URLS.size()<10)
adapter.URLS.add(tpi.thumb);

}

if(jp.getCurrentName().equals("rank")){
tpi.rank=jp.getIntValue();
}

if(jp.getCurrentName().equals("grade")){
tpi.grade=jp.getIntValue();
}

if(jp.getCurrentName().equals("loc")){
jp.nextValue().toString();
tpi.loc[0]=(int) (jp.getFloatValue()*1E6);
jp.nextValue().toString();
tpi.loc[1]=(int) (jp.getFloatValue()*1E6);
jp.nextValue();
publishProgress(new GeoPoint (tpi.loc[0],tpi.loc[1]));

}

jp.nextValue();
}



//tpl.i.add(new TPortItem(tpi.sha, tpi.loc,tpi.age, tpi.date,tpi.thumb, tpi.rank, tpi.grade));


}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

@Override
protected void onProgressUpdate(Object... values) {
super.onProgressUpdate(values);
marker.addOverlay(new OverlayItem((GeoPoint) values[0], "Hola, Mundo!", "I'm in Mexico City!"));
mapOverlays.add(marker); // adding the whole overlays (list) on the maps


}


@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mapView.invalidate();
//gridview.setAdapter(adapter);
}
}

最佳答案

MapView 可以处理的叠加项数量是有限制的。没有关于此限制的官方消息,但一段时间后,您会在缩放/平移期间看到缓慢的行为。

一些解决方案是:

  • > LazyLoading of MapView
  • 只加载尽可能多的可见标记,根据缩放级别和跨度执行此操作。
  • 10 个 99 点叠加层比 1 个 990 点叠加层更快。

关于Android ItemizedOverlay<OverlayItem> 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7927185/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com