Windows Phone - get zoom level from distance

2019-05-26 23:35发布

问题:

I am not good at math so please help me with this. I have distance in meters and I need to calculate zoom level and center to map from this. How can I do that? I started with this but now I am completly lost:

var sCoord = new GeoCoordinate(startPoint.X, startPoint.Y);
var eCoord = new GeoCoordinate(latitude, longitude);
var distance = sCoord.GetDistanceTo(eCoord);

Thanks

回答1:

If I understated you correctly, you can achieve the goal by using the following code

var start = ...;
var finish = ...;

// Calculate center
var center = new GeoCoordinate((start.Latitude + finish.Latitude) / 2,
     (start.Longitude + finish.Longitude) / 2);
var width = Math.Abs(start.Longitude - finish.Longitude);
var height = Math.Abs(start.Latitude - finish.Latitude);

Map.SetView(new LocationRectangle(center, width, height));