Search code examples
androidgoogle-maps-markersgoogle-maps-android-api-2android-maps-v2

Google Maps how to display my location marker in the custom place?


I would like to display marker for "my location" (blue round one) in custom place as I have an option to select my location from map instead of using one from GPS/Wifi/GSM, is it possible to do with existing Google Maps API on Android? Or maybe somehow extract the asset and display it as custom Marker in the MapView?


Solution

  • I ended up implementing custom marker with such XML which seems to look same as one in Google Maps:

    <?xml version="1.0" encoding="UTF-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
        <shape android:shape="oval">
          <solid android:color="@color/map_my_location_inner" />
        </shape>
      </item>
      <item
          android:bottom="0.5dp"
          android:left="0.5dp"
          android:right="0.5dp"
          android:top="0.5dp">
        <shape android:shape="oval">
          <solid android:color="@color/map_my_location_outer" />
        </shape>
      </item>
      <item
          android:bottom="2dp"
          android:left="2dp"
          android:right="2dp"
          android:top="2dp">
        <shape android:shape="oval">
          <solid android:color="@color/map_my_location_inner" />
        </shape>
      </item>
    </layer-list>
    

    It is not perfect as it will be outdated once Google changes it or doesn't support night mode out of the box but for me and for now, it works. I'm open to any better solutions.