Calculating distances from latitude and longitude

2 posts, 0 answers
  1. Ker
    Ker avatar
    4 posts
    Member since:
    Jul 2010

    Posted 12 Jul 2010 Link to this post

    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.
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 12 Jul 2010 Link to this post

    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
  3. DevCraft banner
Back to Top