-2

I'm working on a project that detect is marker inside circle I have this code but this code is not working in short distances

  double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
  double distance =math.acos(math.sin(lat1)*math.sin(lat2)+math.cos(lat1)*math.cos(lat2)*math.cos(lon2-lon1))*6371;
  return distance;
}
bool isMarkerInsideCircle(Marker marker, Circle circle) {
  double distanceBetweenPoints = calculateDistance(
    marker.position.latitude,
    marker.position.longitude,
    circle.center.latitude,
    circle.center.longitude,
  );
  
  return distanceBetweenPoints <= circle.radius;
}
  • 2
    What are short distances? For what values does it not work as expected? – nvoigt May 22 '23 at 12:11
  • like in neighborhood it returns false value i have circle which have 430 radius and marker but it returns inside value when marker is not in the circle – Burak Eren May 22 '23 at 12:19
  • 2
    So what are the actual values you pass in? – nvoigt May 22 '23 at 12:21
  • i have a 39.910387, 32.813285 center coordinates circle and 32.803268,39.91148 coordinates marker and marker not in the circle but this function returns wrong value – Burak Eren May 22 '23 at 12:28
  • Your marker is like 1'000 kilometers off your circle (circle near Ankara, marker in Irak). What exactly do you expect and how hard is it to check that on your side before opening a question? – MrUpsidown May 22 '23 at 12:42
  • sorry i wrote wrong coordinates marker in 39.91148,32.803268 – Burak Eren May 22 '23 at 13:50
  • Why are you writing your own distance function? Does [`computeDistanceBetween`](https://developers.google.com/maps/documentation/javascript/reference/geometry#spherical.computeDistanceBetween) not work for you? – geocodezip May 22 '23 at 17:07
  • It's still not within a 430m radius. – MrUpsidown May 22 '23 at 19:47
  • https://pub.dev/packages/maps_toolkit – MrUpsidown May 22 '23 at 19:58

1 Answers1

-1

You are not converting your coordinates before you use them in your fomula.

See Calculate distance between 2 GPS coordinates and especially the Dart answer for a conversion function.

nvoigt
  • 75,013
  • 26
  • 93
  • 142