-1

I am trying to set one annotation pin icon to the center of the map to select the source location. But I am not able to find any method to set anchor point of that annotation pin icon as Android SDK provides.

Reference method from Android:

startMarker.SetAnchor(p0, p1);
iam.Carrot
  • 4,976
  • 2
  • 24
  • 71

1 Answers1

0

MapmyIndia Map SDK do have the option to set the anchor point of a marker (Annotation)

marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);

Complete Code:

import com.mmi.layers.Marker;
Marker marker= new Marker(mMapView);
marker.setPosition(geoPoint);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
mMapView.getOverlays().add(marker);
mMapView.invalidate();

Note: Marker must have a Geo point to point its position on the map. The Anchor property defines the markers position with respects to its Geo point on the map. ie. Bottom, Top, Center, etc

If you want to fix your marker position to the center of the map, the best way to do that is:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.mmi.MapmyIndiaMapView
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <View
            android:id="@+id/guideline"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_centerInParent="true"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/your_pin_marker"
            android:layout_above="@+id/guideline"
            android:layout_centerHorizontal="true"
            />

    </RelativeLayout>

If you have a Pin/ Pointer type of Marker you will want to bottom of the pointer to point the center of the map. Thats is why I have used a guideline view.

If your marker is round. ie. You want the center of the marker to be at the center of the map, then simply use the image view and marker its gravity as center.

Now your marker will always point to maps center, to get the position you can simply write

mMapView.getMapCenter()
Sahil Sharma
  • 117
  • 1
  • 4