Questions tagged [haversine]

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes.

429 questions
1143
votes
49 answers

Calculate distance between two latitude-longitude points? (Haversine formula)

How do I calculate the distance between two points specified by latitude and longitude? For clarification, I'd like the distance in kilometers; the points use the WGS84 system and I'd like to understand the relative accuracies of the approaches…
Robin Minto
  • 15,027
  • 4
  • 37
  • 40
185
votes
13 answers

Measuring the distance between two coordinates in PHP

Hi I have the need to calculate the distance between two points having the lat and long. I would like to avoid any call to external API. I tried to implement the Haversine Formula in PHP: Here is the code: class CoordDistance { public $lat_a =…
maxdangelo
  • 3,063
  • 5
  • 21
  • 25
155
votes
12 answers

Haversine formula in Python (bearing and distance between two GPS points)

Problem I would like to know how to get the distance and bearing between two GPS points. I have researched on the haversine distance. Someone told me that I could also find the bearing using the same data. Everything is working fine, but the…
avitex
  • 2,478
  • 3
  • 22
  • 22
56
votes
7 answers

Fast Haversine Approximation (Python/Pandas)

Each row in a Pandas dataframe contains lat/lng coordinates of 2 points. Using the Python code below, calculating the distances between these 2 points for many (millions) of rows takes a very long time! Considering that the 2 points are under 50…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
41
votes
9 answers

Using the Haversine Formula in Javascript

I'm trying to use the Haversine Distance Formula (as found here: http://www.movable-type.co.uk/scripts/latlong.html) but I can't get it to work, please see the following code function test() { var lat2 = 42.741; var lon2 = -71.3161; …
Creights
  • 907
  • 1
  • 12
  • 25
31
votes
8 answers

CLLocation Category for Calculating Bearing w/ Haversine function

I'm trying to write a category for CLLocation to return the bearing to another CLLocation. I believe I'm doing something wrong with the formula (calculous is not my strong suit). The returned bearing is always off. I've been looking at this question…
Nick
  • 8,483
  • 10
  • 46
  • 65
25
votes
5 answers

Haversine formula with php

I want to use this formula with php. I have a database with some values of latitute and longitude saved. I want to find, with a certain value of latitude and longitude in input, all the distances (in km) from this point with each point in the…
user1938352
24
votes
1 answer

Pandas Latitude-Longitude to distance between successive rows

I have the following in a Pandas DataFrame in Python 2.7: Ser_Numb LAT LONG 1 74.166061 30.512811 2 72.249672 33.427724 3 67.499828 37.937264 4 84.253715 69.328767 5 72.104828 33.823462 6 …
edesz
  • 11,756
  • 22
  • 75
  • 123
22
votes
1 answer

Querying MySQL for latitude and longitude coordinates that are within a given mile radius

I currently have a MySQL table that is structured as follows: id name lon lat ----- ----- ----------- ----------- 1 Mark -76.316528 40.036027 2 John -95.995102 41.25716 3 …
Lance
  • 4,736
  • 16
  • 53
  • 90
16
votes
3 answers

How to transform a distance from degrees to metres?

I'm using OpenLayers with an ordinary mercator map and I'm trying to sample a bounding box by finding a grid of points in latlong. The bbox is expressed in latlon, e.g. 48.1388,-15.3616,55.2057,-3.9359 I can define a distance in degrees (e.g. x:…
Mulone
  • 3,603
  • 9
  • 47
  • 69
16
votes
1 answer

Vectorised Haversine formula with a pandas dataframe

I know that to find the distance between two latitude, longitude points I need to use the haversine function: def haversine(lon1, lat1, lon2, lat2): lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) dlon = lon2 - lon1 dlat…
user3755536
  • 191
  • 1
  • 2
  • 8
13
votes
3 answers

How to filter a django model with latitude and longitude coordinates that fall within a certain radius

I have the following model. class Location(models.Model): name = models.CharField(max_length = 128, blank = True) address =models.CharField(max_length = 200, blank= True) latitude = models.DecimalField(max_digits=6, decimal_places=3) …
deadlock
  • 7,048
  • 14
  • 67
  • 115
12
votes
2 answers

Spring Query: Haversine formula with pageable

I'm trying to use the Haversine formula to find entities near to a location in a Spring Data JPA Query with Pageable but I dont get it done. My first approach looks like this @Query("SELECT m, (6371 * acos(cos(radians(:latitude)) *…
krinklesaurus
  • 1,606
  • 3
  • 21
  • 38
11
votes
6 answers

Haversine distance calculation between two points in Laravel

I'm working on a Laravel application in which I need to find all the products within a certain radius of the user's coordinates. Products have a one-to-many relationship with users so that users can have multiple products. I've found that the…
Robke22
  • 111
  • 1
  • 1
  • 3
9
votes
2 answers

Pandas Dataframe: join items in range based on their geo coordinates (longitude and latitude)

I got a dataframe that contains places with their latitude and longitude. Imagine for example cities. df = pd.DataFrame([{'city':"Berlin", 'lat':52.5243700, 'lng':13.4105300}, {'city':"Potsdam", 'lat':52.3988600,…
Matthias
  • 5,574
  • 8
  • 61
  • 121
1
2 3
28 29