filipehd filipehd - 26 days ago 5x
Android Question

How to draw markers inside a specific radius for google maps in android

I have a Google Map fragment on my android application.

I have markers drawn on the map which represent places of interest and I have an extra functionality that draws a circle on the center with a radius defined by the user.

What I want to do is that only the markers which are contained inside this circle shall be displayed on map. I am using the Circle object, from Google maps Shapes, to draw the circle.

The problem is that, although the center of the circle is defined in Latitude/Longitude coordinates, it's radius is defined in meters. So how can I calculate if a position of a place in LatLng is contained within a radius defined in meters?

Thank you


All you need is to calculate if two LatLngs are closer to each other than radius.

For that you can use Location.distanceBetween.

See the Circle.contains function here for an example.