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

How can I change?

1 Answer 97 Views
Map
This is a migrated thread and some comments may be shown as answers.
Pavel Ruslanovich Kovyev
Top achievements
Rank 1
Pavel Ruslanovich Kovyev asked on 20 Jul 2010, 12:12 PM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 20 Jul 2010, 04:05 PM
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
Tags
Map
Asked by
Pavel Ruslanovich Kovyev
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or