0

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;
}
}
birgit
  • 1,121
  • 2
  • 21
  • 39

4 Answers4

0

try to change your constructor like this

public OsmItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
    }
Hardik Nadiyapara
  • 2,436
  • 2
  • 17
  • 24
  • This is the constructor as I had it working in the Google Maps Example but the method boundCenterBottom is not defined in OSMdroid... that's why I followed threads like this http://stackoverflow.com/questions/9667208/ – birgit Oct 11 '12 at 14:37
0

I've never used osmdroid, but looking at documentation in here, it shows setMarkerHotspot() as method of OverlayItem, and the documentation in enter link description here says that default marker is always botton center aligned.

So to solve it, you will need to assign a marker to each overlay item added, and set the setMarkerHotspot() to center.

Something like this should solve the issue:

Context mContext; 
Drawable mDefaultMarker;

public OsmItemizedOverlay(Drawable defaultMarker, Context context) { 
      mContext = context;  
      mDefaultMarker = defaultMarker;  
} 

public void addOverlay(OverlayItem overlay) {
    overlay.setMarkerHotspot(HotspotPlace.CENTER);
    mOverlays.add(overlay);   
    populate();   
}  

good luck.

Luis
  • 11,978
  • 3
  • 27
  • 35
0

Simply change your addItem function to:

public void addItem(OverlayItem item) {
    item.setMarkerHotspot(HotspotPlace.CENTER);
    mOverlay.addItem(item);
}
0
use following constructor:

  public OsmItemizedOverlay(Drawable defaultMarker, Context context) {
            super(defaultMarker,context);
            mContext = context;
        }

public void addOverlay(OverlayItem overlay) {
    mOverlays.add(overlay);
    populate();
}
Raj Kumar
  • 402
  • 4
  • 9