Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since no one answered this question correctly..</p> <p>For some reason, the normal Overlay class wasn't working for me the way it should have. I switched to ItemizedOverlay and now everything is perfect.</p> <p>I'm no Android expert so I'd like someone with better experience to comment on this but, I feel that ItemizedOverlay is much better than the simple Overlay. With itemizedoverlay, zooming in and out of the mapview with an object drawn at a fixed point works the way it should, the pin (object) stays exactly where it should stay (that wasn't the case previously).</p> <p>Here's some code for those who are looking for it. This is of course incomplete, and for a specific purpose, but you get the general idea.</p> <p>`class CustomOverlay extends com.google.android.maps.ItemizedOverlay { private ArrayList mOverlays = new ArrayList(); Context mContext;</p> <pre><code> public CustomOverlay(Drawable defaultMarker) { super(defaultMarker); } 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(); } public CustomOverlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); mContext = context; } @Override public boolean onTouchEvent(MotionEvent event, MapView mapView) { if (event.getAction() == 1) { p = mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY()); gc = new Geocoder(getBaseContext(), Locale.getDefault()); try { address = gc.getFromLocation( (double) p.getLatitudeE6() / 1E6, (double) p.getLongitudeE6() / 1E6, 1); addressfound = true; } catch (IOException e) { addressfound = false; e.printStackTrace(); } if (address.size() != 0) { l1 = address.get(0).getAddressLine(0); l2 = address.get(0).getAddressLine(1); l3 = address.get(0).getAddressLine(2); } OverlayItem point = new OverlayItem(p, "Location", l1 + ", " + l2 + ", " + l3); List&lt;Overlay&gt; mapOverlays = mapView.getOverlays(); Drawable drawable = getBaseContext().getResources() .getDrawable(R.drawable.androidmarker); CustomOverlay itemizedoverlay = new CustomOverlay(drawable, getBaseContext()); itemizedoverlay.addOverlay(point); mapOverlays.clear(); mapOverlays.add(itemizedoverlay); mapView.invalidate(); }` </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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