In map applications we usually use a marker to mark a location. In Android map applications also there is a way to put a marker on the map. I’ll explain the process which put a marker on the map. We use an image of a marker for this purpose. There are some classes we need to import. They are as follows.
import android.graphics.drawable.Drawable;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
- The image of the marker keeps in the resource folder. So, first of all we have to create a Drawable object using that image.
Drawable defaultMarker = getResources().getDrawable(R.drawable.pushpin);
- The location which we need to put the marker is included in a GeoPoint object.
- This GeopPoint is an Overlay item which we place on the overlay of map.
- When we creating an OverlayItem in addition to the GeopPoint we add some other information about the location as well.
- The marker is actually created at the point we add the OverlayItem to the ItemizedOverlay.
- We can add several OverlayItems on to a particular ItemizedOverlay
- Finally this ItemizedOverlay is added on to the Overlay on the map view.