Android HelloGoogleMaps to OSMdroid (Open Street Maps)
- by birgit
I am trying to reproduce a working HelloGoogleMaps app in Open Street Maps - but I have trouble including the itemized overlay in OSMdroid.
I have looked at several resources but I cannot figure out how to fix the error on OsmItemizedOverlay - I guess I am constructing OsmItemizedOverlay wrongly or have a mixup with OsmItemizedOverlay and ItemizedOverlay? But everything I tried to change just raised more errors...
"Implicit super constructor ItemizedOverlay() is undefined. Must explicitly invoke another constructor"
"Cannot make a static reference to the non-static method setMarker(Drawable) from the type OverlayItem" - I hope someone can help me getting the class definition straight?
Thanks so much!
package com.example.osmdroiddemomap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import org.osmdroid.api.IMapView;
import org.osmdroid.views.*;
import org.osmdroid.views.overlay.*;
import org.osmdroid.views.overlay.OverlayItem.HotspotPlace;
public class OsmItemizedOverlay extends ItemizedOverlay<OverlayItem> {
Context mContext;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
//ERRORS are raised by the following 3 lines:
public OsmItemizedOverlay(Drawable defaultMarker, Context context) {
OverlayItem.setMarker(defaultMarker);
OverlayItem.setMarkerHotspot(HotspotPlace.CENTER);
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
@Override
public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3) {
// TODO Auto-generated method stub
return false;
}
}