pek*_*his 2 android refresh itemizedoverlay android-mapview
我在Treasure Quest工作,引导用户通过一个ruote.我在地图中显示当前位置时遇到问题,其中也显示了任务点
我扩展了ItemizedOverlay
public class QuestItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays= new ArrayList<OverlayItem>();
public QuestItemizedOverlay(Drawable defaultmarker) {
super(boundCenterBottom(defaultmarker));
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
public void removeItem(int index) {
mOverlays.remove(index);
populate();
}
@Override
public int size() {
return mOverlays.size();
}
}
Run Code Online (Sandbox Code Playgroud)
当我的位置改变时,我得到了听众:
private final LocationListener locationlistener= new LocationListener() {
public void onLocationChanged(Location location) {
Log.i("LOCATION_UPDATED","");
updateWithNewLocation(location);
mapview.invalidate();
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) { }
public void onStatusChanged(String provider, int sttus, Bundle extras) { }
};
Run Code Online (Sandbox Code Playgroud)
并且updatewithNewlocation方法具有以下代码:
private void updateWithNewLocation(Location location) {
Double curlat=location.getLatitude();
Double curlong=location.getLongitude();
GeoPoint point=new GeoPoint((int)(curlong*1E6),(int) (curlat*1E6));
OverlayItem overlayitem=new OverlayItem(point,"I'm here","This is where you are");
Drawable marker=this.getResources().getDrawable(R.drawable.eplogo_marker);
overlayitem.setMarker(marker);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.clear();
mapOverlays.add(itemizedoverlay);
}
Run Code Online (Sandbox Code Playgroud)
使用DDMS进行调试(只是测试),监听器工作正常,我的mapview mOverlays随着我用DDMS更改位置而增长,但是当我调用mapview.invalidate()时,没有发生
哪个是刷新mapview的方法?
还有一个问题,如果mapOverlay有多个带有标记的itemized覆盖,会发生什么?
提前致谢
@pekechis:更新mapOverLays(添加新的等)后,只需调用即可
mapView.postInvalidate();
Run Code Online (Sandbox Code Playgroud)
这将刷新地图视图.你的问题也可能是因为没有在UI线程中调用它,例如那样
mActivity.runOnUiThread(new Runnable() {
public void run() {
mapView.postInvalidate();
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5005 次 |
| 最近记录: |