Skip to content

Haversine #25

Answered by cyberprophet
cyberprophet asked this question in Q&A
Jun 20, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote
import 'dart:math' show cos, sqrt, asin;

class Marker {
  final double lat;
  final double lng;

  Marker(this.lat, this.lng);
}

// 내 위치의 좌표
final double myLat = 내_위치_위도;
final double myLng = 내_위치_경도;

// 마커들의 좌표 리스트
final List<Marker> markerCoords = [
  Marker(마커1_위도, 마커1_경도),
  Marker(마커2_위도, 마커2_경도),
  // ...
];

// 반경 1km에 있는 마커들을 담을 리스트
final List<Marker> markersWithinRadius = [];

// Haversine 공식을 사용하여 거리 계산
double getDistance(double lat1, double lng1, double lat2, double lng2) {
  const double earthRadius = 6371.0; // 지구 반지름 (단위: km)

  final double dLat = _toRad(lat2 - lat1);
  final double dLng = _toRad(lng2 - lng1);

  final double a =
      sin(dLat / 2) * sin(dLat / 2) +
      

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@cyberprophet
Comment options

cyberprophet Jun 20, 2023
Maintainer Author

Answer selected by cyberprophet
@cyberprophet
Comment options

cyberprophet Jun 20, 2023
Maintainer Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant