Issue
I have ran through this tutorial a couple times and tried to get an item to show up on my map but cant seem to get anywhere with it. To my understanding i dont have any of my code wrong but if anyone may be able to see why my item will not overlay my map that would be awesome.
this is my mapview:
public class HelloMapViewActivity extends MapActivity {
@Override
protected boolean isRouteDisplayed()
{
return false;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
GeoPoint point = new GeoPoint(34420800, -119698200);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, HelloMapViewActivity.this);
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
MapController mapcontroller = mapView.getController();
mapcontroller.animateTo(point);
mapcontroller.setZoom(15);
}
}
here is the itemizedoverlay class as well:
public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(defaultMarker);
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();
}
@Override
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;
}
}
i have really just followed the tutorial and everything looks like its right but it will load the map just no item will be on it where i set my point. there are no errors as well. any help would be great
Solution
Add following constructor to HelloItemizedOverlay class.
public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
Answered By - Ravi Bhatt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.