haversine

Is Google Maps calculating the wrong distance?

I've managed to get two functions working to calculate distances between two point on a google map. One that I gleaned(stole) from various places on the web and the other using the GLatLng.distanceFrom method in the Google Maps API. The reason I'm using two functions is because I noticed something odd about the results I was getting fo...

Best method for working out locations within a radius of starting point

I'm aiming to create a feature in my latest project preferably using PHP. When each user signs up they are going to input their postcode. Then hopefully I will be converting this to lat/long using Open Street Map. Anyway, I want to be able to find out other users located near the current user. I have seen a lot of people using the Have...

How to Return Additional Columns With Values Generated in Stored Procedures On the 'Fly'?

This is one of those questions where I'm having a hard time figuring out how to ask it so bare with me. I have a stored procedure in SQL 2005 that calculates distance using the Haversine formula. Everything works quite nicely but I'd like to return the calculated distance with my result set. How do I go about adding that column/value p...

Distance between two locations using Latitude and Longitude way off what Google says.

I've spent a few days trying to figure this one out and can't seem to pinpoint the problems. I have a SQL 2005 database storing latitude and longitude as Decimal(18,8), all of which I received by querying Google. For these two locations: From: 10715 Downsville Pike Ste 100 MD 21740 to: 444 East College Ave Ste 120 State College PA, 168...

Is it possible to implement the Haversine formula in Objective-C and call it from SQLite?

As I understand, SQLite doesn't have the math functions to properly implement the Haversine formula in straight SQL. I'm thinking this should be possible using an external function, with the implementation being in C. The goal is to have a SQLite database in an iPhone, and to be able to sort by the distance to the user's current locati...

Calculating Great-Circle Distance with SQLite

Here is my problem, I have a SQLite table with locations and latitudes / longitudes. Basically I need to: SELECT location, HAVERSINE(lat, lon) AS distance FROM location ORDER BY distance ASC; HAVERSINE() is a PHP function that should return the Great-Circle Distance (in miles or km) given a pair of latitude and longitude values. One o...

Add radius to Longitude and Latitude with C#

Hello, I need to generate a bounding box of min and max latitude and longitude values so I can return addresses within a given radius. I have two func<>'s below to return the range I need to +/- to the lon lat coordinates to establish the bounding box. However I don't think the math is 100% I am using the Haversine formula to generat...

Django Sort By Calculated Field

Using the distance logic from this SO post, I'm getting back a properly-filtered set of objects with this code: class LocationManager(models.Manager): def nearby_locations(self, latitude, longitude, radius, max_results=100, use_miles=True): if use_miles: distance_unit = 3959 else: distance_uni...

How to calculate short & long distance via Haversine?

Hi, I am looking for a way to calculate the distance between 2 points on the globe. We've been told to use Haversine, which works fine to calculate the shortest distance between the 2 points. Now, I'd like to calculate the "long distance" between to points. So suppose you have 2 cities, A in the west and B in the east. I want to know t...

Calculate compass heading to a CLLocation - Haversine functions for iOS

I understand how to get the distance between 2 CLLocations. I need to determine the generalized compass bearing (N, NE, E etc.) from a CLLocation to another CLLocation. Before I implement something to derive the bearing with the haversine formula is there a generally adapted open source library or code fragment that you've found solves ...

Distance between two locations isn't right

I have used the algorithm on http://www.movable-type.co.uk/scripts/latlong.html to find the distance between two points. My two points are long1 = 51.507467; lat1 = -0.08776; long2 = 51.508736; lat2 = -0.08612; According to Movable Type Script the answer is 0.1812km My application gives the result (d) as 0.230km // Haversine formu...

Doubts in converting spherical coordinates

I'm trying to convert spherical coordinates (namely latitude and longitude from a GPS device) into Cartesian coordinates. I'm following this simple conversion derived from the polar coordinates conversion equations. Then I'm calculating the distance between the two point applying the euclidean distance but the value I'm finding is not a...

Combine NamedQuery and Criteria in Hibernate

I use Hibernate in a storefinder application. For the proximity search in SQL I use the haversine formula. Because this is a bit messy SQL I created a named SQL query in my .hbm.xml File for this. SELECT location.*, ( 3959 * acos( cos( radians(7.4481481) ) * cos( radians( X(location.coordinates) ) ) * cos( radians( ...

Geolocation and Haversine formula

I am trying to create a basic web application that detects the users geolocation, queries a mySQL database, and returns all bus stops within say 5 kilometers. The GTFS feed including the Longitude and Latitude have been inserted into a mySQL database, and I found a example HTML page that provides the Longitude and Latitude of the browse...

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 and tried applying the changes that were accepted as a correct answer and the webpage i...

__CIasin and Is Arcsine much slower than sine in .NET?

I've been running som eprofile tests of a slow area of code. This is with Visual Studio 2008 and .NET 2 (fully patched). About 32% of my computation is used by the Haversine formula. This requires two sines, two cosines, a square root, and an arc sine - all using the standard .NET Math library (ie. Math.Sin, Math.Asin, Math.Sqrt). I've b...

zipcode distance range formula. Which formula is correct?

I need to find all the zipcodes with a certain range from a zipcode. I have all the zipcode lat/lon in a DB. I have found two formulas online that vary slightly from each other. Which one is correct? Formula 1: def latRange = range/69.172 def lonRange = Math.abs(range/(Math.cos(Math.toRadians(zip.latitude)) * 69.172)); def minLat = ...