Я делаю, приложение React Native использует Карты и работает с БД Firebase в реальном времени, чтобы получить все данные, содержащие широту, долготу и т. Д.
Я получаю текущее местоположение [широта и долгота], вычисляю расстояниемежду текущим местоположением и ближайшим, в который я захожу с TurfJs
Моя проблема заключается в том, что мне нужно отобразить всех пользователей из БД, которые находятся ближе всего к моему текущему местоположению.но функция просто получает первый ближайший!Как справиться с этим?
Узел ![Node](https://i.stack.imgur.com/1mpAa.png)
Функция
handleNearby = () => {
const { region, providers } = this.state;
let points = providers.map(p =>
turf.point([p.coordinates.latitude, p.coordinates.longitude])
);
let collection = turf.featureCollection(points);
let currentPoint = turf.point([region.longitude, region.latitude]);
let nearest = turf.nearestPoint(currentPoint, collection);
let addToMap = [currentPoint, points, nearest];
console.log(nearest);
console.log(Math.floor(nearest.properties.distanceToPoint)); // let's say 50Km
};
<MapView
style={[styles.map, { width: this.state.width }]}
style={StyleSheet.absoluteFill}
// onMapReady={() => console.log(this.state.region)}
showsUserLocation={true}
region={region}
loadingEnabled={true}
// style={StyleSheet.absoluteFill}
textStyle={{ color: "#bc8b00" }}
containerStyle={{ backgroundColor: "white", borderColor: "#BC8B00" }}
>
<Marker
coordinate={region}
title="Hello"
description="description"
pinColor="navy"
// onPress={() => alert("Provider Profile")}
// icon={require('../assets/camera-icon.png')}
onCalloutPress={() => alert("Provider Profile")}
/>
//
{this.state.providers.map((marker, index) => (
<Marker
key={index}
coordinate={marker.coordinates}
title={marker.username}
/>
))}
// Nearest Point Marker Should Be Here
</MapView>;