Search code examples
androidgoogle-mapsgoogle-maps-markers

How do I make an image pin in google maps center align with the location rather than bottom align in Android


I am making an android app and I have an image marker (a circle). When it is on the map, the bottom of the circle aligns with the location, rather than the center of the circle. How would I fix this?

mMap!!.addMarker(
                MarkerOptions().position(LatLng(location!!.latitude, location!!.longitude)).title("Me").snippet("My Location").icon(
                    BitmapDescriptorFactory.fromResource(R.drawable.circle)
                )
            )

Solution

  • You can locate with this parameter:

    .anchor(x, y)
    

    Example usage:

    googleMap.addMarker(new MarkerOptions()
                        .position(new LatLng(latitude, longitude))
                        .anchor(0.5f, 1.0f)
                        .title("title")
                        .snippet("snippet"));