The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes.
Questions tagged [haversine]
429 questions
0
votes
1 answer
Variable already define in scope?
Hi I am having issues implementing a method I made to calculate distance in Java using the Haversine formula.
The section that I am trying to implement it in is:
if(gps.canGetLocation()){
double latitude1 =…

Max Stow
- 3
- 1
- 2
0
votes
2 answers
Google Maps Circle / MySQL query
I would like to draw a circle on a map, and get all rows in my database with geo the lat/lng points that fall into that circle.
I don't want draw the circle using google.maps.Circle as that applies mercator projection distortion. I want a geometric…

bradley
- 776
- 2
- 11
- 29
0
votes
2 answers
MySQL - How to speed up search with using geolocation data?
I have a table with cars and I am trying to find all cars in a city within a radius. Here's a query I am using for this:
SELECT cars.*,
69.0 * HAVERSINE(cars.latitude,cars.longitude, 32.7802618, -96.80097810000001) AS distance
FROM cars
WHERE…

user2932090
- 331
- 2
- 7
- 16
0
votes
0 answers
Using haversine formula to find distance between two points in C#?
So i was trying to duplicate the distance formula on this page in C#.
http://www.movable-type.co.uk/scripts/latlong.html
This is for distance between two coordinates.
This is my code
int R = 6371;
double Lat1 =…

user1775297
- 87
- 11
0
votes
2 answers
Issues with a result from calculating latitude/longitude from haversine formula in C++
So right now, I'm doing a homework assignment for a C++ class. The assignment says that I need to calculate the distance between two places using the haversine formula based on an input of degrees given by the user for longitude and latitude. Then…

Alex
- 2,145
- 6
- 36
- 72
0
votes
1 answer
point to line using angles and haversine with 3 lat long points
I wish to get the distance to a line and started using haversine code.
private static final double _eQuatorialEarthRadius = 6378.1370D;
private static final double _d2r = (Math.PI / 180D);
private static double PRECISION = 0.001;
//…

Tomsmith
- 15
- 7
0
votes
0 answers
Mysql nearest location order by distance and using two tables
I need to search and order by distance asc using two tables.
Explained:
Table 1: companies
Id, CompanyName, address, location (point datatype)
Table 2 : branches
Id, companyID, address, location (point datatype)
Table 1 is companies main data, main…

lorenzo gonzalez
- 1,894
- 4
- 14
- 18
0
votes
1 answer
Haversine formula not working correctly
This is my code for the Haversine formula based off of this and the answer of this question:
$scope.getCoordDistance = function (myLat, myLon, locLat, locLon) {
var lat2 = 41.894993;
var lon2 = -88.459239;
var lat1 =…

Ian Pennebaker
- 233
- 4
- 15
0
votes
2 answers
AngularJS Getting distance between multiple coordinates
Im writing an app that has a ton of locations, all with coordinates, I want the app to be able to search for the locations by name, or by which one is closest. I know how to determine the distance between two coordinates via the haversine formula.…

Ian Pennebaker
- 233
- 4
- 15
0
votes
0 answers
mysqli prepared statements - not all results are binding
I'm having some problems returning the $distance from a prepared statement. The $station_id is echoed out and all is well there but the distance is empty.
I've also replaced the question marks and ran the query directly in phpmyadmin and it returns…

jmood
- 77
- 2
- 9
0
votes
3 answers
Sort by distance on multiple zipcode PHP & MySql
Hi Friends I need help on this logic
Problem Definition:
There are 4 tables:
Project
Project Name
Project Id
Zipcode
Vendor
Vendor Id
Vendor Name
Phone
Service area distance
Vendor Service Areas
Vendor Id
Service area zipcode
Zipcode…

Akash Nand
- 1
- 1
0
votes
3 answers
Duplicate Records in MySQL Geo Search Using Cross Join and Hversine Formula
I'm trying to complete a modification of this Google tutorial
I've written this SQL to query a table of locations using the location "name." Given the name of the location, the query returns pizza restaurants within the proximity. To accomplish this…

Brandon Buster
- 1,195
- 1
- 9
- 12
0
votes
0 answers
MySQL User Defined Function - Haversine Formula
I have the following code:
CREATE FUNCTION CalculateDistance
(`Code1` VARCHAR(8), `Code2` VARCHAR(8)) RETURNS FLOAT
BEGIN
DECLARE Code1Lat FLOAT;
DECLARE Code1Long FLOAT;
DECLARE Code2Lat FLOAT;
DECLARE Code2Long FLOAT;
…

user2879284
- 1
- 2
0
votes
1 answer
SQL meta joins plus Haversine formular
I have a query which joins a few meta datas to a user.
SELECT
users.*,
gender.meta_value AS `gender`,
sexual_orientation.meta_value AS `sexual_orientation`,
…

Luke Snowden
- 4,056
- 2
- 37
- 70
0
votes
0 answers
Haversine Formula - why the absolute value?
I'm trying to calculate the distance from a lat, lon using haversine formula. For some reason this only works in the northern hemisphere and I'm suspecting its because of the abs. Once I remove the absolute value, the code works fine. So I was just…

dudemanbearpig
- 1,264
- 3
- 12
- 19