Reputation: 357
I have a database that stores markers latitude and longitude. I have a class that so far has my current location and I want to be able to show all the markers within a certain radius of my current location. I access markers by doing something similar to this.
List <Markers> markers = db.getAllMarkers();
I'm not sure how to obtain the radius and check if any of my markers are within the radius. Any advice would be greatly appreciated.
Upvotes: 1
Views: 1384
Reputation: 11258
If you have current location (as a center of circle) and each marker has position you can use
method computeDistanceBetween()
from geometry library. See spherical library docs. It returns the distance between two LatLngs. So, if distance is less than radius, marker is in...
Note: It takes as arguments two LatLng objects and the 3rd argument is a default Earth radius.
Upvotes: 1