Estoy haciendo un sitio web de búsqueda de ubicación cercana. Estoy tratando de mostrar las 5 ubicaciones más cercanas comenzando desde la más cercana a la más lejana usando un bucle. pero obtengo el mismo resultado de ubicación. Quiero 5 ubicaciones diferentes y todavía estoy confundido sobre cómo resolverlo. uso este paquete en el mapa npm ubicación más cercana
const [myLocation, setMylocation] = useState(null); const [status, setStatus] = useState(null); const [dapat, setDapat] = useState([]); useEffect(() => { getLocation(); }, []); useEffect(async() => { const response = await axios.get(Urlfromdatabase); let locations = [] response.data.map((user) => { locations.push({ "name": user.name, "address": user.address, "phone": (user.phone).toString(), "facility": user.facility, "lat": Number(user.lat), "lng": Number(user.lng) }) return locations }) if (myLocation) { var nearestLocations = []; for (let step = 0; step < 5; step++) { if (locations.length === 0) break; let nearest = findNearestLocation(myLocation, locations); nearestLocations.push(nearest); locations = locations.filter(function (location) { return (location.lat !== nearest.lat && location.lng !== nearest.lng); }); } setDapat(nearestLocations); console.log(nearestLocations); } }, [myLocation]); const getLocation = () => { if (!navigator.geolocation) { setStatus('geolocation not support on your browser!!'); } else { setStatus('locating...!!'); navigator.geolocation.getCurrentPosition((position) => { setStatus(null); setMylocation({ lat: position.coords.latitude, lng: position.coords.longitude }) }, () => { setStatus('can't get the location!'); }); }