Note that there are some explanatory texts on larger screens.

plurals
  1. POItemizedOverlay Issues (HelloMapView Tutorial)
    text
    copied!<p>I am having trouble with the Hello Map Views tutorial from the Android Developer website: <a href="http://developer.android.com/resources/tutorials/views/hello-mapview.html" rel="nofollow noreferrer">http://developer.android.com/resources/tutorials/views/hello-mapview.html</a></p> <p>My first problem was that upon clicking the overlay item, the application would crash. This problem was solved by making sure to pass the context to the ItemizedOverlay class that I created...</p> <p>After I fixed this problem, the icon for the overlay does not display in the map. I am able to click on the map where the overlay is located and the dialog box displays. Unfortunately, I cannot see the icon. I have made sure that the image that I reference is an object located in the R.java resources file. In fact my exact problem is asked by the poster of the following thread after going through the same issues. Unfortunately his second question was never answered. <a href="https://stackoverflow.com/questions/3531964/context-null-pointer">Context null Pointer</a></p> <p>Here is my MapView class:</p> <pre><code>package com.mapsExample; import java.util.List; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; import com.google.android.maps.OverlayItem; public class HelloMaps extends MapActivity { /** 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); List&lt;Overlay&gt; mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker); HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this); GeoPoint point = new GeoPoint(19240000,-99120000); OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!"); itemizedoverlay.addOverlay(overlayitem); mapOverlays.add(itemizedoverlay); } @Override protected boolean isRouteDisplayed() { return false; } } </code></pre> <p>And my ItemizedOverlay class:</p> <pre><code>package com.mapsExample; import java.util.ArrayList; import android.app.AlertDialog; import android.content.Context; import android.graphics.drawable.Drawable; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.OverlayItem; public class HelloItemizedOverlay extends ItemizedOverlay { private ArrayList&lt;OverlayItem&gt; mOverlays = new ArrayList&lt;OverlayItem&gt;(); Context mContext; public HelloItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); } 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; } } </code></pre> <p>Again, If I do not pass 'this' to the ItemizedOverlay constructor, the icon displays but cannot be clicked. Any help is much appreciated. Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload