This is a migrated thread and some comments may be shown as answers.

Calculating distances from latitude and longitude

1 Answer 131 Views
Map
This is a migrated thread and some comments may be shown as answers.
Ker
Top achievements
Rank 1
Ker asked on 12 Jul 2010, 10:52 AM
I am doing a silverlight bing map application. In the application it have two textboxes and one button. Does anyone know how to make it to C# code when user input latitude and longitude of two places, and find out the distance between them.

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 12 Jul 2010, 06:04 PM
Hi Ker,

You can use LocationRect object for calculating distance between two locations. The sample code is the following:
Location location1 = new Location(37.7040701207995, -121.882780875908); 
Location location2 = new Location(37.7140701207995, -121.872780875908); 
    
Location northEast = new Location( 
    Math.Max(location1.Latitude, location2.Latitude), 
    Math.Max(location2.Longitude, location2.Longitude)); 
    
Location southWest = new Location( 
    Math.Min(location1.Latitude, location2.Latitude), 
    Math.Min(location1.Longitude, location2.Longitude)); 
    
LocationRect rect = new LocationRect(northEast, southWest); 
rect.MapControl = this.radMap; 
    
double distance = Math.Sqrt(rect.Width * rect.Width + rect.Height * rect.Height); 

Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Map
Asked by
Ker
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or