【问题标题】:How to remove current location pin from map in android, keeping other pins如何从android中的地图中删除当前位置引脚,保留其他引脚
【发布时间】:2012-01-26 17:52:48
【问题描述】:

我有一张地图,目前我经常根据用户的 GPS 位置在地图上放置一个自定义图钉,这也取决于他们的位置何时发生变化,但 GPS 在这里有点不稳定它相当多。目前,每次发生这种情况时,都会在地图上放置一个新图钉。我想删除前一个图钉,以便在地图上只显示用户位置的一个图钉,就像用户位置的实时表示一样。

除此之外。是否可以在地图上有一组单独的图钉(它们的位置永远不会改变)并确保在用户位置更新时它们也不会被清除。

代码中的任何其他 cmets 将不胜感激。

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;
}

}

【问题讨论】:

    标签: android google-maps android-mapview mapactivity


    【解决方案1】:

    如果你想添加一个跟随用户当前位置的 Pin,你可以使用 com.google.android.maps.MyLocationOverlay ....这也为你提供了所需的监听器。你也可以覆盖它的 onDraw()方法来绘制您的自定义图钉。然后您可以像添加任何其他叠加层一样添加此叠加层...不要忘记调用 myLocationOverlay.enableMyLocation() 以便您收到位置更改。

    【讨论】:

      猜你喜欢
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      相关资源
      最近更新 更多