.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Calculate distance, bearing and more between Latitude/Longitude points

Posted By: Syed Shakeer Hussain     Posted Date: July 17, 2010    Points: 2   Category :Others
This page presents a variety of calculations for latitude/longitude points, with the formulæ and code fragments for implementing them.

All these formulæ are for calculations on the basis of a spherical earth (ignoring ellipsoidal effects) - which is accurate enough* for most purposes. [In fact, the earth is very slightly ellipsoidal; using a spherical model gives errors typically up to 0.3% - see notes for further details].

View Complete Post

More Related Resource Links

How to calculate the distance between two points on the Earth

We offer many Global Database Products that you can use with the below formulas to calculate distances and many other uses. Not sure how to use distance calculations or global databases within your company? See our Global Database Examples for more information on how to use our data within your industry. Be sure to Download a Free Sample of one of our many Global Database Products.

Find Mile Distance From 2 zipcodes (I have the Latitude and Longitude for both)

Could someone please show me how the query would look? I have 2 zip codes with their Latitude and Longitude.  I want in miles how far away is A from B.

Find location based on longitude and latitude



can you explain a bit more about  using google map api in asp.net3.5 using c#.

and please tell me one thing how to give latitude and longitude and identify the location (from givinglongitude and latitude).

Calculate GPS Distance with SQL?

CREATE TABLE [dbo].[Logs](

    [logDate] [datetime] NOT NULL,
    [logType] [int] NOT NULL,
    [logCacher] [varchar](128) NOT NULL,
    [cacheId] [int) NOT NULL,

CREATE TABLE [dbo].[Caches](

    [cacheId] [int] NOT NULL,
    [cacheName] [varchar](128) NOT NULL,
    [latitude] [float] NOT NULL,
    [longitude] [float] NOT NULL,

Some sample data:

INSERT INTO Caches VALUES ( 1, 'cache1', 38.1, -9.1 )
INSERT INTO Caches VALUES ( 2, 'cache2', 38.2, -9.2 )
INSERT INTO Caches VALUES ( 3, 'cache3', 38.3, -9.3 )
INSERT INTO Caches VALUES ( 4, 'cache4', 38.4, -9.4 )
INSERT INTO Caches VALUES ( 5, 'cache5', 38.5, -9.5 )

INSERT INTO Logs VALUES ( '21/11/2007 00:00', 1, 'geocacher1', 1 )
INSERT INTO Logs VALUES ( '21/11/2007 10:00', 1, 'geocacher1', 2 )
INSERT INTO Logs VALUES ( '22/11/2007 00:00', 1, 'geocacher1', 3 )
INSERT INTO Logs VALUES ( '22/11/2007 10:00', 1, 'geocacher1', 4 )
INSERT INTO Logs VALUES ( '23/11/2007 00:00', 1, 'geocacher1', 5 )

INSERT INTO Logs VALUES ( '23/11/2007 00:00', 1, 'geocacher2', 1 )

issue in calculating Distance by latitude and longtitude



I am just stuck in the strange calculation.

i am trying to find distance by latitude and longtitude by using this formula mentioned in this site.


every thing is Ok there when i do it by calculator but when i started doing it by programmatically there is a diiference in result.

here is my part of code

lat = Convert.ToDouble( (s3[a]));
                longt =Convert.ToDouble( (s4[a]));
                Avg_lat = pc._Latitude - lat;
                Avg_longt = pc._Longitude - longt;
                a_hold =( Math.Sin(Avg_lat / 2) * Math.Sin(Avg_lat / 2) )+ (Math.Cos(pc._Latitude) * Math.Cos(lat)) * (Math.Sin(Avg_longt / 2) * Math.Sin(Avg_longt / 2));
                c_hold = 2 * Math.Atan2(Math.Sqrt(a_hold), Math.Sqrt(1 - a_hold));

Logic to calculate business hours


Hi All,

I have tried searching all over the web for this logic. Got many but half of them did not match what i was looking for and half were malfunctioning.

I want to calculate business working hours between 2 datetime, where in I should be able to set the working hours as well as weekends and holidays should not be calculated.


Please help me guys... It will be a great help... 

Data Points: Deny Table Access to the Entity Framework Without Causing a Mutiny


Julie Lerman shows database administrators how to limit access to databases from the Entity Framework by allowing it to work only with views and stored procedures instead of tables-without impacting application code or alienating developers.

Julie Lerman

MSDN Magazine August 2010

Data Points: Windows Azure Table Storage - Not Your Father's Database


Let go of your traditional relational database thinking if you want to understand how Windows Azure Table storage works, says Julie Lerman. Luckily for you, she's done the hard work to grasp the new concepts and help you get up to speed.

Julie Lerman

MSDN Magazine July 2010

Data Points: LINQ Projection Queries and Alternatives in WCF Services


LINQ's ability to project randomly shaped data into anonymous types can be a blessing and a source of frustration, says Julie Lerman. It's great when you just need to grab a special view of your data, but it can be problematic in certain circumstances. She explains what the limitations are and how to get around them.

Julie Lerman

MSDN Magazine May 2010

Data Points: Precompiling LINQ Queries


Did you know that by precompiling LINQ queries you might actually be degrading your app's performance if you're not careful? Julie Lerman explains how to ensure you're not re-precompiling queries each time and losing the expected performance benefits across post-backs, short-lived service operations and other code where critical instances are going out of scope.

Julie Lerman

MSDN Magazine March 2010

Data Points: Data Validation with Silverlight 3 and the DataForm


In this month's column, John Papa shows you how the DataForm control works and how it can be customized.  He presents in detail a sample application that uses several features to bind, navigate, edit and validate data using the DataForm.

John Papa

MSDN Magazine October 2009

Data Points: Data Performance and Fault Strategies in Silverlight 3


In this month's column, the author shows how binary encoding works, the effect it has on an application's performance, and how it behaves by demonstrating it in action.

John Papa

MSDN Magazine August 2009

Data Points: Building An Out-of-Browser Client With Silverlight 3


Silverlight 2 applications are restricted to running inside a browser. However, Silverlight 3 applications can run inside the browser or out. Here we build a social networking app as a standalone Silverlight 3 application.

John Papa

MSDN Magazine June 2009

Data Points: Using Silverlight 2 With ADO.NET Data Services


ADO.NET Data Services and Silverlight make a powerful combination, but to make them work well together, there are a few things you need to understand. Here, John Papa explains.

John Papa

MSDN Magazine April 2009

Data Points: Syndicated Data And Isolated Storage In Silverlight


Here we build a syndicated news reader application to illustrate the use of isolated storage and data syndication in Silverlight.

John Papa

MSDN Magazine February 2009

Data Points: Cloud Gazing From Silverlight 2


John Papa tackles questions about calling services from Silverlight 2 applications.

John Papa

MSDN Magazine November 2008

Data Points: Service-Driven Apps With Silverlight 2 And WCF


Here John Papa demonstrates how to build a Silverlight 2 user interface that communicates through WCF to interact with business entities and a database.

John Papa

MSDN Magazine September 2008

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend