Windows Phone - get zoom level from distance

社会主义新天地 提交于 2019-12-07 22:30:24

问题


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));


来源:https://stackoverflow.com/questions/18085382/windows-phone-get-zoom-level-from-distance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!