【发布时间】:2017-01-29 18:55:36
【问题描述】:
您好,我正在开发一个 xamarin 形式的应用程序,该应用程序需要获取 gps 位置并将纬度和经度组合成 forcast.io 的 url 我正在使用 James Montemagno 的 Geolocator 插件并遵循自述文件,但我我仍然收到这些错误:
严重性代码描述项目文件行抑制状态 错误 CS0165 使用未分配的局部变量“msi”
严重性代码描述项目文件行抑制状态 错误 CS0266 无法隐式转换类型 'Plugin.Geolocator.Abstractions.IGeolocator' 到 'Plugin.Geolocator.CrossGeolocator'。存在显式转换 (你错过了演员吗?)
严重性代码描述项目文件行抑制状态 错误 CS1061 'CrossGeolocator' 不包含 'IsGeolocationEnabled' 并且没有扩展方法 'IsGeolocationEnabled' 可以找到接受“CrossGeolocator”类型的第一个参数 (您是否缺少 using 指令或程序集引用?)
严重性代码描述项目文件行抑制状态 错误 CS1061 'CrossGeolocator' 不包含 'GetPositionAsync' 并且没有扩展方法 'GetPositionAsync' 可以找到接受“CrossGeolocator”类型的第一个参数 (您是否缺少 using 指令或程序集引用?)
严重性代码描述项目文件行抑制状态 错误 CS1061 'CrossGeolocator' 不包含 'DesiredAccuracy' 和没有扩展方法 'DesiredAccuracy' 接受 可以找到“CrossGeolocator”类型的第一个参数(你是 缺少 using 指令或程序集引用?)
然后是雷达代码:
using Xamarin.Forms;
using System;
using System.Diagnostics;
using Plugin.Geolocator;
namespace AppName.Radar
{
public interface MyLocationTracker
{
void ObtainMyLocation();
event EventHandler<MyLocationEventArgs> locationObtained;
}
public interface MyLocationEventArgs
{
double lat { get; set; }
double lng { get; set; }
}
public partial class RadarHome : ContentPage
{
private readonly CrossGeolocator _locator;
private double BetaLat;
private double BetaLog;
public RadarHome()
{
MyLocationTracker msi;
_locator = CrossGeolocator.Current;
if (_locator.IsGeolocationEnabled == false)
{
if (Device.OS == TargetPlatform.Android)
{
msi.locationObtained += (object Esender, MyLocationEventArgs ew) =>
{
Debug.WriteLine(ew.lat);
};
msi.ObtainMyLocation();
}
else if (Device.OS == TargetPlatform.iOS)
{
msi = DependencyService.Get<MyLocationTracker>();
msi.locationObtained += (object Jsender, MyLocationEventArgs je) =>
{
Debug.WriteLine(je.lat);
};
msi.ObtainMyLocation();
}
}
_locator.DesiredAccuracy = 50;
GetPositionAsynchronously();
string str = string.Format(
"https://forecast.io/?mobile=1#/f/Lat:{0} , Long: {1}", BetaLat, BetaLog);
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri(str);
}
private async void GetPositionAsynchronously()
{
//will run asynchronously in a diff thread
var position = await _locator.GetPositionAsync(timeoutMilliseconds: 100000);
BetaLat = position.Latitude; //will work
BetaLog = position.Longitude; // will work
}
}
}
我在所有 3 个平台(Froms、iOS、Android)上都安装了最新的 Geolocator nuget 包
提前致谢!
【问题讨论】:
标签: xamarin xamarin.forms