【发布时间】:2012-05-24 18:31:56
【问题描述】:
我有一个 MapActivity,我可以在其中获取当前位置并在其上固定一个可绘制对象。问题是,当我的位置发生变化( onchangedlocation 方法)时,地图上会出现另一个精确点,但第一个点并没有消失。另一个问题是 onchangedlocation 在我触摸屏幕之前不会固定另一个可绘制对象。我该怎么做才能立即出现。我想用这个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);
这是我的位置改变了
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(geopoint),但我真的不知道该怎么做。
如果您能帮助我解决这两个问题,我将不胜感激。谢谢!
PS:当设备在汽车中或以某种速度行驶的东西时,我需要可绘制对象看起来像它正在持续移动。
【问题讨论】:
标签: android map location drawable overlayitem