유저랑 북마크의 위치를 비교할때

해당위치가 같은데도 불구하고 fale가 나오는 현상 발생

{
"triggered": false
}

알고보니 geolib의 라이브러리에 대한 정보 부족

getDistance랑 isPointWithinRadius의 차이

 const result1 = getDistance(
          {
            latitude: user_direction.latitude,
            longitude: user_direction.longitude,
          },
          {
            latitude: Number(bookmark.latitude),
            longitude: Number(bookmark.longitude),
          }, // 반경 5m 내에 있는지 체크
        );
        console.log('거리', result1);
        const result = isPointWithinRadius(
          {
            latitude: user_direction.latitude,
            longitude: user_direction.longitude,
          },
          {
            latitude: Number(bookmark.latitude),
            longitude: Number(bookmark.longitude),
          },
          5, // 반경 5m 내에 있는지 체크
        );
        

getDistance 위도 경도의 거리를 계산해주는 geolib의 레포지토리

isPointWithinRadius 위도 경도끼리 반경 몇km 내에 있는지 체크

로직이 문제가 있었던게 아니라 위도경도 위치가 5m차이가 난다고 생각했지만

실제 거리는 120km이상 차이가 났기 때문에 위도 경도의 포멧을 잘 알면 좋겠다..! << (일단 하드코딩으로 강제로 위치 확인)

위도 경도를 못읽고있었다!

===========================
35.8449152
127.0775808
===========================
35.1799710
128.1523160
===========================
122322
결과 false

35.8449152
127.0775808
===========================
35.1799710
128.1523160
===========================
122.322km
결과 true

5 = 5m
5000 = 5km
5 = 0.005km

객체형태로 반환되지 않는 문제 발생

// 5m 이내의 북마커 중 가장 가까운 것 하나만 반환
      let nearestBookmarkP: any = allData.flat(); // 중첩 배열을 단일 배열로 변환
      console.log('nearestBookmarkP1', nearestBookmarkP);
      nearestBookmarkP = nearestBookmarkP.filter((bookmark: any) => {
        bookmark = JSON.parse(bookmark); // JSON.parse 하나를 객체로 만들려고 하는거 //왜안되는지 찾으쇼
        if (bookmark.latitude && bookmark.longitude) {
          return bookmark;
        }
      }); // 유효한 데이터 필터링
      console.log('nearestBookmarkP2', nearestBookmarkP);
      nearestBookmarkP = nearestBookmarkP.map((bookmark: any) => {
        bookmark = JSON.parse(bookmark);
        console.log('=================================================');
        console.log('user_direction.latitude', user_direction.latitude);
        console.log('user_direction.longitude', user_direction.longitude);
        console.log('=================================================');
        console.log('bookmark.latitude', bookmark.latitude);
        console.log('bookmark.longitude', bookmark.longitude);
        console.log('=================================================');
        const distance = getDistance(
          {
            latitude: user_direction.latitude,
            longitude: user_direction.longitude,
          },
          {
            latitude: parseFloat(bookmark.latitude),
            longitude: parseFloat(bookmark.longitude),
          },
        );
        console.log('bookmark', bookmark, typeof bookmark);
        console.log('distance', distance);
        const test = { ...bookmark };
        console.log('test', test);
        return { ...bookmark, distance };
      });
      console.log('nearestBookmarkP3', nearestBookmarkP);
      nearestBookmarkP = nearestBookmarkP
        .filter((bookmark) => bookmark.distance <= 5) // 5m 이내만 필터링
        .sort((a, b) => a.distance - b.distance) // 가장 가까운 순으로 정렬
        .at(0); // 가장 가까운 하나만 가져오기

      console.log('결과:', nearestBookmarkP);

객체로 받아오고싶은데 안받아와지는 문제 발생

JSON.parse를 이용해서 해당 문자열을 객체로 반환해줌

배열안에 있는 객체로 map을 돌려서 해당하는 객체를 뽑아냄