私は現在、ユーザーの GPS 位置からカスタム ピンをマップ上に頻繁に配置するマップを持っています。これは、ユーザーの位置がいつ変化するかにも依存しますが、ここでは GPS が少し途切れ途切れになっているため、かなりうまくいきます多く。現時点では、これが発生するたびに新しいピンがマップに配置されます。ユーザーの位置のライブ表現のように、ユーザーの場所の 1 つのピンだけがマップに表示されるように、前のピンを削除したいと考えています。
それに加えて。マップ上に別のピンのセット (位置が変更されない) を設定し、ユーザーの位置が更新されたときにピンがクリアされないようにすることは可能ですか?
コードに関するその他のコメントをいただければ幸いです。
Imports...
public class MapOne extends MapActivity implements LocationListener {
... fields
@Override
protected void onCreate(Bundle icicle) {
....onCreate initialisations
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
compass.disableCompass();
lm.removeUpdates(this);
super.onPause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
compass.enableCompass();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 20, this);
super.onResume();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
public void onLocationChanged(Location l) {
// TODO Auto-generated method stub
lat = (int)(l.getLatitude() *1E6);
longi = (int)(l.getLongitude() *1E6) ;
GeoPoint ourLocation = new GeoPoint(lat, longi);
OverlayItem overlayItem = new OverlayItem(ourLocation, "Hey!", "What's up!?");
CustomPinpoint custom = new CustomPinpoint(customMarker, Map.this);
custom.insertPinpoint(overlayItem);
overlayList.add(custom);
}
}
必要に応じて参照用のクラスを特定します。
public class Pinpoint 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);
setC(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();
}
public Context getC() {
return c;
}
public void setC(Context c) {
this.c = c;
}
}