0

I am new to use osm in android.I have successfully show OSM in android.But i have no idea " how to click on marker and show marker detail like google map v2 infowindow popup".

How to show marker details with image onclick marker openstreetmap android, same as Google map Infowindow show on marker click.

Please give me code or idea to implement marker click event in osm android.

Thank you in advance.

This is my code which i have implemented in android java

public class MainActivity extends Activity 
{
private MapView mapView;
private MapController mapController;    
LocationManager locationManager;

ArrayList<OverlayItem> overlayItemArray;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mapView = (MapView)findViewById(R.id.mapview);

    mapView.setBuiltInZoomControls(true);
    mapView.setMultiTouchControls(true);
    mapView.setClickable(true);
    //mapView.setUseDataConnection(false);
    mapController = (MapController) mapView.getController();
    mapController.setZoom(17);

    //--- Create Overlay
    overlayItemArray = new ArrayList<OverlayItem>();

    DefaultResourceProxyImpl defaultResourceProxyImpl = new DefaultResourceProxyImpl(this);
    MyItemizedIconOverlay myItemizedIconOverlay = new MyItemizedIconOverlay(overlayItemArray, null, defaultResourceProxyImpl);
    mapView.getOverlays().add(myItemizedIconOverlay);
    //---

    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    //for demo, getLastKnownLocation from GPS only, not from NETWORK
    Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if(lastLocation != null)
    {
        updateLoc(lastLocation);
    }

    //Add Scale Bar
    ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
    mapView.getOverlays().add(myScaleBarOverlay);
}

@Override
protected void onResume()
{
    super.onResume();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, myLocationListener);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, myLocationListener);
}

@Override
protected void onPause() 
{
    super.onPause();
    locationManager.removeUpdates(myLocationListener);
}

private void updateLoc(Location loc)
{
    GeoPoint locGeoPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude());
    mapController.setCenter(locGeoPoint);
    mapController.animateTo(locGeoPoint);

    setOverlayLoc(loc);

    mapView.invalidate();
}

private void setOverlayLoc(Location overlayloc)
{
    GeoPoint overlocGeoPoint = new GeoPoint(overlayloc);
    //---
    overlayItemArray.clear();

    OverlayItem newMyLocationItem = new OverlayItem("My Location", "My Location", overlocGeoPoint);
    overlayItemArray.add(newMyLocationItem);
    //---
}

private LocationListener myLocationListener = new LocationListener()
{
    @Override
    public void onLocationChanged(Location location)
    {
        updateLoc(location);
    }

    @Override
    public void onProviderDisabled(String provider)
    {           
    }

    @Override
    public void onProviderEnabled(String provider)
    {           
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)
    {           
    }
};

private class MyItemizedIconOverlay extends ItemizedIconOverlay<OverlayItem>
{

    public MyItemizedIconOverlay(List<OverlayItem> pList,org.osmdroid.views.overlay.ItemizedIconOverlay.OnItemGestureListener<OverlayItem> pOnItemGestureListener,
            ResourceProxy pResourceProxy)
    {
        super(pList, pOnItemGestureListener, pResourceProxy);           
    }

    @Override
    public void draw(Canvas canvas, MapView mapview, boolean arg2)
    {
        super.draw(canvas, mapview, arg2);

        if(!overlayItemArray.isEmpty())
        {
            //overlayItemArray have only ONE element only, so I hard code to get(0)
            GeoPoint in = overlayItemArray.get(0).getPoint();

            Point out = new Point();
            mapview.getProjection().toPixels(in, out);

            Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
            canvas.drawBitmap(bm,out.x - bm.getWidth()/2,out.y - bm.getHeight()/2,null);
        }
    }

    @Override
    public boolean onSingleTapUp(MotionEvent event, MapView mapView)
    {
        //return super.onSingleTapUp(event, mapView);
        return true;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent event, MapView mapView)
    {
        return true;
    }
}

}

asked 30 Dec '14, 09:16

nehalkumar's gravatar image

nehalkumar
31337
accept rate: 0%

edited 30 Dec '14, 10:22

SomeoneElse's gravatar image

SomeoneElse ♦
33.0k65343778

Can you explain what you've done so far to "show OSM in android"? Are you writing an Android application, and if so in what - Android Java, or something else?

(30 Dec '14, 09:21) SomeoneElse ♦

i have added code please check and give suggestion.Yes this is android apllication

(30 Dec '14, 09:29) nehalkumar

One Answer:
1
permanent link

answered 30 Dec '14, 10:16

nehalkumar's gravatar image

nehalkumar
31337
accept rate: 0%

edited 30 Dec '14, 10:17

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×585
×167
×79
×44

question asked: 30 Dec '14, 09:16

question was seen: 29,508 times

last updated: 30 Dec '14, 10:22

powered by OSQA