如何在Xamarin.Forms.Map中获取当前位置或移动到当前位置 [英] How to get current location or move to current location in Xamarin.Forms.Map
本文介绍了如何在Xamarin.Forms.Map中获取当前位置或移动到当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于地图已经显示了用户位置(使用IsShowingUser),所以我只想缩放到该位置.这很容易实现,还是因为我找不到任何GeoLocation对象,所以我需要获取每个平台上的位置.只有GeoCoder ... 这不是放大用户位置的常见用例吗?
Since the Map already shows the user location (with IsShowingUser) I just want to zoom to this location. Is this easily possible or do I need to get the location on every platform, since I don't find any GeoLocation object. Only the GeoCoder... Is this not a common usecase to zoom to users position?
推荐答案
您需要使用感兴趣的位置调用MoveToRegion
方法.
You will need to call MoveToRegion
method with the position you are interested in.
您可以使用用于Xamarin的Geoolocator插件获取PCL项目中的位置:
You can use Geolocator Plugin for Xamarin to get the location in PCL project:
var locator = CrossGeolocator.Current;
var position = await locator.GetPositionAsync(10000);
map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position. Longitude),
Distance.FromMiles(1))
这篇关于如何在Xamarin.Forms.Map中获取当前位置或移动到当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文