我有一個MapActivity,在那裏我得到當前的位置,並且我在它上面畫一個可繪製的。事情是,當我的位置改變(onchangedlocation方法)時,地圖上會出現另一個精確位置,但第一個不會消失。另一個問題是,在我觸摸屏幕之前,更改位置不會釘住另一個drawable。我該怎麼做才能立即出現。我想用這個drawable來顯示汽車的當前位置,所以它應該像GPS或其他東西一樣正常移動。我在醫院的位置有多個可繪圖
這是我的活動,我添加了精確點。
public class CustomPinpoint extends ItemizedOverlay<OverlayItem>{
private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
private Context c;
public CustomPinpoint(Drawable defaultMarker) {
super(boundCenter(defaultMarker));
// TODO Auto-generated constructor stub
}
public CustomPinpoint(Drawable m, Context context) {
// TODO Auto-generated constructor stub
this(m);
c = context;
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return pinpoints.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return pinpoints.size();
}
public void insertPinpoint(OverlayItem item){
pinpoints.add(item);
this.populate();
}
}
,我在我的onCreate方法使用:
lm= (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria crit = new Criteria();
towers = lm.getBestProvider(crit, false);
final Location location = lm.getLastKnownLocation(towers);
if(location != null){
latit = (int) (location.getLatitude() *1E6);
longi = (int) (location.getLongitude() *1E6);
ourLocation = new GeoPoint(latit, longi);
controller.animateTo(ourLocation);
controller.setZoom(14);
if//myItemizedOverlay.addItem(ourLocation, "myPoint1", "myPoint1");
OverlayItem overlayItem = new OverlayItem(ourLocation, "What's up", "2nd String");
CustomPinpoint custom = new CustomPinpoint(d, Map.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);}
map.setSatellite(false);
map.setStreetView(true);
,這是我onlocationchanged
public void onLocationChanged(Location l) {
// TODO Auto-generated method stub
latit = (int) (l.getLatitude() *1E6);
longi = (int) (l.getLongitude() *1E6);
GeoPoint ourLocation = new GeoPoint(latit, longi);
OverlayItem overlayItem = new OverlayItem(ourLocation, "What's up", "2nd String");
CustomPinpoint custom = new CustomPinpoint(d, Map.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
}
我想對我的當前位置的多個可繪製一個解決辦法是隻顯示最後一個pinpoint(地點點)添加,但我真的不知道如何做到這一點。
如果你能幫我解決這兩個問題,我將不勝感激。謝謝 ! PS:我會需要可繪製的外觀,當設備在汽車中時,它會繼續移動或者以某種速度前進。