Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove current location pin from map in android, keeping other pins
    primarykey
    data
    text
    <p>I have a map which at the moment I place a custom pin on the map every so often from the GPS position of the user, this is also dependent on when their position changes but with the GPS being a bit choppy here it does it quite a lot. At the moment a new pin is placed on the map every time this happens. I want to remove the previous pin so that just the one pin for the users location is shown on the map, like a live representation of the users position.</p> <p>In addition to this. Is it possible to have a separate set of pins on the map (which their positions never change) and ensure they are not also cleared when the users position is updated.</p> <p>Any other comments on the code would be appreciated.</p> <pre><code>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); } } </code></pre> <p>Pinpoint class for reference if required.</p> <pre><code>public class Pinpoint extends ItemizedOverlay&lt;OverlayItem&gt; { private ArrayList&lt;OverlayItem&gt; pinpoints = new ArrayList&lt;OverlayItem&gt;(); 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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload