2012-01-26 10 views
0

私は現在、ユーザーの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; 
} 

} 

答えて

0

あなたは、ユーザーの現在位置を次のピンを追加したい場合は、これはalso.Youも上書きすることができます必要なリスナーを提供します.... com.google.android.maps.MyLocationOverlayを使用することができますあなたのカスタムピンを描画するためのonDraw()メソッドです。次に、他のオーバーレイのようにこのオーバーレイを追加できます。myLocationOverlay.enableMyLocation()を呼び出して場所の変更を受け取ることを忘れないでください。

関連する問題