Is it possible to find nearest location to a given location

2 posts, 1 answers
  1. Rod Yager
    Rod Yager avatar
    79 posts
    Member since:
    May 2010

    Posted 10 Nov 2010 Link to this post

    Say I have a collection of locations and I want to find out which one is the closest to another specified location, how would I do this?

  2. Answer
    Andrey avatar
    1681 posts

    Posted 12 Nov 2010 Link to this post

    Hi Rod Yager,

    You can find out the closest point to the location using calculation of distance between the location and elements of the collection. You can create the LocationRect instance from two locations and then calculate a distance using Width and Height properties.

    The sample method is below.
    private Location GetNearestLocation(LocationCollection collection, Location point)
        double minDistance = double.PositiveInfinity;
        Location nearestLocation = Location.Empty;

    foreach (Location location in collection)
            LocationRect rect = new LocationRect(location, point);
            rect.MapControl = this.radMap;

    double distance = Math.Sqrt(rect.Width * rect.Width + rect.Height * rect.Height);

    if (distance < minDistance)
                minDistance = distance;
                nearestLocation = location;

    return nearestLocation;

    Best wishes,
    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 R3 2016 release webinar banner
Back to Top