Center map between two points WinRT

陌路散爱 提交于 2019-12-25 03:26:43

问题


im trying to center the windows phone map between two points, adjusting center and zoom to make that points visible at the same time.

Im Android and IOS there are functions to do it, as example this is how to do it in Android:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(myPos.getPosition());
builder.include(defaultPos.getPosition());
mapa.animateCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 50));

How can i do the same in WinRT?

Thanks in advance.


回答1:


If you are targeting Windows Phone 8.1 instead of WinRT (Windows 8/8.1) then you can do the following:

var geoboundingBox = new Windows.Devices.Geolocation.GeoboundingBox(
new BasicGeoposition() { Latitude = 40, Longitude = -90 }, 
new BasicGeoposition() { Latitude = 45, Longitude = -100 });
map.TrySetViewAsync(new Geopoint(geoboundingBox.Center));



回答2:


For the Bing Maps WinRT control you can do this in two different ways. The first is to create a LocationRect from the two points. This will create a bounding box for your locations. You can either set the map view to this LocationRect using the SetView method on the map which will center and zoom to these locations, or you can use the Center property of this LocationRect to set the view of the map such that it is centered on these two locations, without zooming into the map. Something like this should work:

var bounds = new LocationRect(new Location(40,-90), new Location(45,-100));
map.SetView(bounds.Center);

Another method requires a bit more calculation but a good option to know if you come across other map controls that don't have an easy solution like the first one I mentioned. This method consists of calculating the center coordinate between the two locations. I have a blog post on how to do this from a vey old version of Bing Maps here: http://rbrundritt.wordpress.com/2008/10/14/calculating-the-midpoint-of-a-line-segment/ The logic can be easily migrated to other programming languages.

It sounds like you are new to developing with Bing Maps in WinRT. I recommend checking out my free ebook on how to create location intelligent Windows Store apps. It goes into a lot of detail on how to create great apps using the Bing Maps control. You can download a copy of it here: http://rbrundritt.wordpress.com/my-book/



来源:https://stackoverflow.com/questions/25422894/center-map-between-two-points-winrt

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