Skip to content Skip to sidebar Skip to footer

Can't Mark While Showing The Current Location In 'mapview'

Hear is my project In my project I am showing my current location,showing the current lat-long.But I'm not able to mark my current position in android. Thnx in advance. @Override

Solution 1:

mapController.animateTo(point);
mapController.setZoom(16);
MapOverlay mapOverLay=new MapOverlay();
mapOverLay.setPointToDraw(point);
List<Overlay> listOfOverlays=map.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverLay);

Replace the above lines with below lines//where lat and long are fetched from gps.

Drawable srcdrawable = getApplicationContext().getResources().getDrawable(R.drawable.pin_blue);
CustomItemizedOverlay srcitemizedOverlay = new CustomItemizedOverlay(srcdrawable, getApplicationContext());
GeoPoint srcpoint = new GeoPoint((int)( Double.parseDouble(lat) * 1E6),(int)( Double.parseDouble(lng)* 1E6));
OverlayItem srcoverlayitem = new OverlayItem(srcpoint, "Hello!", "This is your Location.");
srcitemizedOverlay.addOverlay(srcoverlayitem);
mapView.getOverlays().clear();
mapView.getOverlays().add(srcitemizedOverlay);
mapController.animateTo(srcpoint);
mapController.setZoom(16);

//If you want more than one point on map /*

Drawable srcdrawable = getApplicationContext().getResources().getDrawable(R.drawable.pin_blue);
CustomItemizedOverlay srcitemizedOverlay = new CustomItemizedOverlay(srcdrawable, getApplicationContext());
forloop(setoflocations){
GeoPoint srcpoint = new GeoPoint((int)( Double.parseDouble(lat) * 1E6),(int)( Double.parseDouble(lng)* 1E6));
OverlayItem srcoverlayitem = new OverlayItem(srcpoint, "Hello!", "This is your Location.");
if(srcitemizedOverlay!=null && mapController!=null){
srcitemizedOverlay.addOverlay(overlayitem);
mapController.animateTo(point);
animatePoint = point;
}
}
mapView.getOverlays().clear();
mapView.getOverlays().add(srcitemizedOverlay);

*/

also use the below CustomItemizedOverlay.java class

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private final ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

    private Context context;

    public CustomItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }

    public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
        this(defaultMarker);
        this.context = context;
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mapOverlays.get(i);
    }

    @Override
    public int size() {
        return mapOverlays.size();
    }

    public void addOverlay(OverlayItem overlay) {
        mapOverlays.add(overlay);
        this.populate();
    }

}

Solution 2:

add overlay Icon on current location

 myItemizedOverlay.addItem(point , "myPoint1", "myPoint1");
             m_mapView.getOverlays().add(myItemizedOverlay);

mapController.animateTo(point);

Post a Comment for "Can't Mark While Showing The Current Location In 'mapview'"