[英]Get device location in latitude-longitude in xamarin forms
I have a scanner in my application, and as I am scanning any QR code I need to get a current location of device in latitude-longitude.我的应用程序中有一个扫描仪,当我扫描任何二维码时,我需要在经纬度中获取设备的当前位置。 I don't have any idea how to get location so I don't have any piece of code right now.
我不知道如何获取位置,所以我现在没有任何代码。 Suggest me some ways to get location on scanning completion of QR code.
建议我一些方法来在扫描完成 QR 码时获取位置。
Geolocator Plugin example:地理定位器插件示例:
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync (timeoutMilliseconds: 10000);
Console.WriteLine ("Position Status: {0}", position.Timestamp);
Console.WriteLine ("Position Latitude: {0}", position.Latitude);
Console.WriteLine ("Position Longitude: {0}", position.Longitude);
Ref: https://github.com/jamesmontemagno/GeolocatorPlugin参考: https : //github.com/jamesmontemagno/GeolocatorPlugin
Nuget: https://www.nuget.org/packages/Xam.Plugin.Geolocator Nuget: https ://www.nuget.org/packages/Xam.Plugin.Geolocator
For everyone that is confused about this location stuff I recommend using Xamarin Essentials and not the plug-in mentioned above.对于对此位置内容感到困惑的每个人,我建议使用 Xamarin Essentials 而不是上面提到的插件。
var location = await Geolocation.GetLastKnownLocationAsync();
if (location != null)
{
MyLocation = location;
if (!ShowUserLocation)
ShowUserLocation = true;
}
I recommend Xamarin Essentials.我推荐 Xamarin Essentials。 Look this post and check your permissions.
查看此帖子并检查您的权限。 https://docs.microsoft.com/en-us/xamarin/essentials/geolocation?tabs=android
https://docs.microsoft.com/en-us/xamarin/essentials/geolocation?tabs=android
var Latitude;
var Longitude;
var request = new GeolocationRequest(GeolocationAccuracy.Best);
var location = await Geolocation.GetLocationAsync(request);
if (location != null)
{
if (location.IsFromMockProvider)
{
//Put a message if detect a mock location.
}else
{
Latitude=location.Latitude;
Longitude=location.Longitude;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.