How can I change?

2 posts, 1 answers
  1. Pavel Ruslanovich Kovyev
    Pavel Ruslanovich Kovyev avatar
    14 posts
    Member since:
    May 2010

    Posted 20 Jul 2010 Link to this post

    I have 2 (or more) locations (example lat - 58, lon - 56 and lat - 54, lon - 38). How can I calculate center map and ZoomLevel that this points (locations) was inside map?
  2. Answer
    Andrey avatar
    1681 posts

    Posted 20 Jul 2010 Link to this post

    Hi Pavel Ruslanovich Kovyev,

    You can use the LocationRect class. It has Center property and ZoomLevel property that contains optimal zoom level for the rectangle.
    The sample code of the SetBestView method is below. It specifies Center and ZoomLevel properties of the map control according to collection of locations.
    private void SetBestView(Collection<Location> locations)
        Location location1 = new Location(90, 180);
        Location location2 = new Location(-90, -180);

    foreach (Location location in locations)
            location1.Latitude = Math.Min(location1.Latitude, location.Latitude);
            location1.Longitude = Math.Min(location1.Longitude, location.Longitude);

    location2.Latitude = Math.Max(location2.Latitude, location.Latitude);
            location2.Longitude = Math.Max(location2.Longitude, location.Longitude);

    LocationRect rect = new LocationRect(location1, location2);
        rect.MapControl = this.radMap;

    this.radMap.ZoomLevel = rect.ZoomLevel;
        this.radMap.Center = rect.Center;

    Sincerely yours,
    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
Back to Top