简体   繁体   English

Xamarin Forms Labs Geolocation样本

[英]Xamarin Forms Labs Geolocation sample

I downloaded the source for Xamarin Forms Labs, and was trying to run the geolocator sample for the android project. 我下载了Xamarin Forms Labs的源代码,并试图为android项目运行geolocator示例。 When you click the Get Position button, the location message returned is "Cancelled". 单击“获取位置”按钮时,返回的位置消息为“已取消”。 I tried making a new xamarin forms project in VS by following these steps: file > new project > Xamarin PCL. 我尝试通过以下步骤在VS中创建一个新的xamarin表单项目:file> new project> Xamarin PCL。 When I install xamarin forms labs in that project and use it, I get the same message. 当我在该项目中安装xamarin表单实验室并使用它时,我收到相同的消息。 I can, however, get the Windows Phone example to work. 但是,我可以使用Windows Phone示例。 I'm not sure if maybe the Android emulator that installs with Xamarin can even connect to the network on my machine or not. 我不确定安装Xamarin的Android模拟器是否可以连接到我的机器上的网络。 That would explain why it cant get the location 这可以解释为什么它无法获得该位置

(This is a little late, but just submitting in case anyone finds this via a search) (这有点晚了,但只是提交,万一有人通过搜索找到了这个)

Double check your platform permissions. 仔细检查您的平台权限。

For Android: You must request the following permissions within your Android Project 对于Android:您必须在Android项目中申请以下权限

  1. ACCESS_COARSE_LOCATION
  2. ACCESS_FINE_LOCATION

For iOS: In iOS 8 you now have to call either RequestWhenInUseAuthorization or RequestAlwaysAuthorization on the location manager. 对于iOS:在iOS 8中,您现在必须在位置管理器上调用RequestWhenInUseAuthorizationRequestAlwaysAuthorization

Additionally you need to add either the concisely named NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription to your Info.plist . 此外,您需要将简要命名的NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescriptionInfo.plist

For Windows Phone: You must set the ID_CAP_LOCATION permission. 对于Windows Phone:您必须设置ID_CAP_LOCATION权限。

Xamarin Forms If you are developing a Xamarin Forms app, you could try using the Geolocator (Xamarin.Plugin) sample, just remember to add your permissions :) Xamarin表单如果您正在开发Xamarin Forms应用程序,您可以尝试使用Geolocator(Xamarin.Plugin)示例,只需记住添加您的权限:)

Sample: 样品:

var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;

var position = await locator.GetPositionAsync (timeout: 10000);

Console.WriteLine ("Position Status: {0}", position.Timestamp);
Console.WriteLine ("Position Latitude: {0}", position.Latitude);
Console.WriteLine ("Position Longitude: {0}", position.Longitude);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin形成带有ListView和复选框的Labs绑定问题 - xamarin forms labs binding issue with listview and checkbox Xamarin Forms WebView 地理位置问题 - Xamarin Forms WebView Geolocation issue Xamarin forms 地理定位错误结果 - Xamarin forms Geolocation wrong results Xamarin,使用Xlabs示例中的Geolocation - Xamarin, using Geolocation from Xlabs sample xamarin表单示例代码发布快速入门 - Sample code issue xamarin forms quick start 无法使用PCLStorage或Xamarin Forms Labs在Android文件系统中创建文件夹/文件 - Not able to create a folder/file in Android file system with PCLStorage or Xamarin Forms Labs Xamarin Forms甚至示例应用程序现在都无法运行 - Xamarin Forms even sample apps now won't run 无法在发布模式下构建Xamarin UrhoSharp.Forms示例项目 - Can't build Xamarin UrhoSharp.Forms sample project in release mode Xamarin.Forms.Android:在编译/部署时使用示例数据文件填充“Environment.SpecialFolder.Personal” - Xamarin.Forms.Android: Populating 'Environment.SpecialFolder.Personal' with sample data files at compilation/deployment 升级到最新的 android/firebase sdk,此 azure 通知中心示例 - xamarin ZAC68B62ABFD6A9FE26E8AC42ZCC8 - Upgrade to lastest android/firebase sdk, this azure notification hub sample - xamarin forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM