I have a query, I have a Json with addresses of locations such as banks, stores, etc.
I want to show those markers on the map as I move, that is, within a radius of 200 meters.
I already have my List and I go through them with a foreach, for now I show them all, in the whole map, but if I had thousands, I would see it inefficient.
I enclose the code to generate the circular radius.
public class MapDrawer {
private GoogleMap map;
private static int EARTH_RADIUS = 6371000;
public MapDrawer(GoogleMap map) {
this.map = map;
}
private LatLng getPoint(LatLng center, int radius, double angle) {
// Get the coordinates of a circle point at the given angle
double east = radius * Math.cos(angle);
double north = radius * Math.sin(angle);
double cLat = center.latitude;
double cLng = center.longitude;
double latRadius = EARTH_RADIUS * Math.cos(cLat / 180 * Math.PI);
double newLat = cLat + (north / EARTH_RADIUS / Math.PI * 180);
double newLng = cLng + (east / latRadius / Math.PI * 180);
return new LatLng(newLat, newLng);
}
public Polygon drawCircle(LatLng center, int radius) {
// Clear the map to remove the previous circle
map.clear();
// Generate the points
List<LatLng> points = new ArrayList<LatLng>();
int totalPonts = 30; // number of corners of the pseudo-circle
for (int i = 0; i < totalPonts; i++) {
points.add(getPoint(center, radius, i*2*Math.PI/totalPonts));
}
// Create and return the polygon
return map.addPolygon(new PolygonOptions().addAll(points).strokeWidth(2).strokeColor(0x700a420b));
}
public static boolean isInPoint(LatLng Point){
for (List<LatLng> charginPoint: chargingPoints)
if (PolyUtil.containsLocation(Point,charginPoint,false))
return true;
return false;
}
public static boolean isOriginOrDestinyInAirport(LatLng origin, LatLng destiny){
return isInPoint(origin) || isInPoint(destiny);
}
}
Greetings.