{
  "id": 363477,
  "title": "Calculate Distance Between Two Coordinates",
  "url": "/competitions/big-data-derby-2022/discussion/363477",
  "author_name": "",
  "post_date": "2022-11-01T19:51:11.676701900Z",
  "votes": null,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hey all!</p>\n<p>If you trying to calculate distance between two coordinates in latitude/longitude, then maybe you want use that function. (You will get distance in kilometers)</p>\n<pre><code> math  sin, cos, sqrt, atan2, radians\n\n ():\n    lat1 = radians(lat1)\n    lon1 = radians(lon1)\n    lat2 = radians(lat2)\n    lon2 = radians(lon2)\n\n    dlon = lon2 - lon1\n    dlat = lat2 - lat1\n\n    R = \n    a = sin(dlat / )** + cos(lat1) * cos(lat2) * sin(dlon / )**\n    c =  * atan2(sqrt(a), sqrt( - a))\n\n     R * c\n</code></pre>\n<p>credit: <a href=\"https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude\" target=\"_blank\">https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude</a></p>\n<p>Good luck :)</p>",
  "messages": [
    {
      "id": "2013305",
      "postDate": "11/01/2022 19:51:11",
      "content": "<p>Hey all!</p>\n<p>If you trying to calculate distance between two coordinates in latitude/longitude, then maybe you want use that function. (You will get distance in kilometers)</p>\n<pre><code> math  sin, cos, sqrt, atan2, radians\n\n ():\n    lat1 = radians(lat1)\n    lon1 = radians(lon1)\n    lat2 = radians(lat2)\n    lon2 = radians(lon2)\n\n    dlon = lon2 - lon1\n    dlat = lat2 - lat1\n\n    R = \n    a = sin(dlat / )** + cos(lat1) * cos(lat2) * sin(dlon / )**\n    c =  * atan2(sqrt(a), sqrt( - a))\n\n     R * c\n</code></pre>\n<p>credit: <a href=\"https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude\" target=\"_blank\">https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude</a></p>\n<p>Good luck :)</p>",
      "rawMarkdown": "Hey all!\n\nIf you trying to calculate distance between two coordinates in latitude/longitude, then maybe you want use that function. (You will get distance in kilometers)\n\n```python\nfrom math import sin, cos, sqrt, atan2, radians\n\ndef calculate_distance_between_coordinates(lat1, lon1, lat2, lon2):\n    lat1 = radians(lat1)\n    lon1 = radians(lon1)\n    lat2 = radians(lat2)\n    lon2 = radians(lon2)\n\n    dlon = lon2 - lon1\n    dlat = lat2 - lat1\n\n    R = 6373.0\n    a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2\n    c = 2 * atan2(sqrt(a), sqrt(1 - a))\n\n    return R * c\n```\n\ncredit: https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude\n\nGood luck :)",
      "votes": null
    },
    {
      "id": "2013344",
      "postDate": "11/01/2022 20:23:35",
      "content": "<p>Thanks for the code!</p>",
      "rawMarkdown": "Thanks for the code!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2013344,
      "author_name": "anashamoutni",
      "author_url": "",
      "post_date": "11/01/2022 20:23:35",
      "content": "<p>Thanks for the code!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2013305": "Hey all!\n\nIf you trying to calculate distance between two coordinates in latitude/longitude, then maybe you want use that function. (You will get distance in kilometers)\n\n```python\nfrom math import sin, cos, sqrt, atan2, radians\n\ndef calculate_distance_between_coordinates(lat1, lon1, lat2, lon2):\n    lat1 = radians(lat1)\n    lon1 = radians(lon1)\n    lat2 = radians(lat2)\n    lon2 = radians(lon2)\n\n    dlon = lon2 - lon1\n    dlat = lat2 - lat1\n\n    R = 6373.0\n    a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2\n    c = 2 * atan2(sqrt(a), sqrt(1 - a))\n\n    return R * c\n```\n\ncredit: https://stackoverflow.com/questions/19412462/getting-distance-between-two-points-based-on-latitude-longitude\n\nGood luck :)",
    "2013344": "Thanks for the code!"
  },
  "source": "meta"
}