Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>adding ItemizedOverlay class would be better if you want to add pin (or images) on top of your map.<br> package com.android.testandroidmap;</p> <pre><code>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;(); private Context mContext; public HelloItemizedOverlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); // TODO Auto-generated constructor stub mContext = context; } @Override protected OverlayItem createItem(int i) { // TODO Auto-generated method stub return mOverlays.get(i); } @Override public int size() { // TODO Auto-generated method stub return mOverlays.size(); } public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); } @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>I get this code from <a href="http://developer.android.com/resources/tutorials/views/hello-mapview.html" rel="nofollow">Android Developer Official Guide</a>, and with this class on your code, you can add the overlays. </p> <p>Add all the things you need (container, image for pins, and the pin+coordinate overlay)</p> <pre><code>List&lt;Overlay&gt; mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker); HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this); </code></pre> <p>for your icons to be recognized by the class before, and also instantiate the coordinate, add the coordinate to an overlayItem + register the overlayItem with the HelloItemizedOverlay you made before </p> <pre><code>GeoPoint point = new GeoPoint(19240000,-99120000); OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!"); itemizedoverlay.addOverlay(overlayitem); </code></pre> <p>finish with adding the overlay to the mapOverlay, which is a collection of overlays.</p> <pre><code>mapOverlays.add(itemizedoverlay); </code></pre> <p>This displays a pin on top of my map, which can be customized by any image you want. If you want to also use different images for each location, just instantiate another Drawable with your image and register that Drawable to other HelloItemizedOverlay. </p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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