xamarin - 模拟 GPS 不更新 lon 和 lat
问题描述
好的,我正在使用 应用商店 andriod 中的Lockito来模拟我的位置,我得到了第一个 long 和 lat 但它没有更新,因为我应该将位置存储在列表中
此处的此函数 locationObtained 似乎没有被多次调用。
我正在使用真实设备进行测试,并已授予位置权限。
private async Task<int> StartGps()
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
{
await DisplayAlert("Need location", "Gunna need that location", "OK");
}
var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
status = results[Permission.Location];
}
ILocation loc = DependencyService.Get<ILocation>();
loc.locationObtained += (object ss, ILocationEventArgs ee) =>
{
lat = ee.lat;
lng = ee.lng;
lbllat.Text = ee.lat.ToString();
lbllong.Text = ee.lng.ToString();
Position position = new Position(lat, lng);
postionsList.Add(position);
};
listPostions.ItemsSource = postionsList;
loc.ObtainMyLocation();
return 1;
}
在我的列表视图中,我有以下内容。
<ListView x:Name="listPostions" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Latitude}"
TextColor="#f35e20" />
<Label Text="{Binding Longitude}"
HorizontalOptions="EndAndExpand"
TextColor="#503026" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
问题是它不会自动更新我的应用程序我已将 lockito 设置为开发人员选项中选择的应用程序我有位置并且可以很好地看到 Lockito 中的移动但我看不到来自 Lockito 的其他坐标进入我的应用程序。
这是我的安卓功能
public class GetMyLocation : Java.Lang.Object, ILocation, ILocationListener
{
public event EventHandler<ILocationEventArgs> locationObtained;
public void ObtainMyLocation()
{
LocationManager lm = (LocationManager)Forms.Context.GetSystemService(Context.LocationService);
lm.RequestLocationUpdates(LocationManager.NetworkProvider,0, 0, this);
}
public void OnLocationChanged(Location location)
{
if (location != null)
{
LocationEventArgs args = new LocationEventArgs();
args.lat = location.Latitude;
args.lng = location.Longitude;
locationObtained(this, args);
}
}
public void OnProviderDisabled(string provider)
{
}
public void OnProviderEnabled(string provider)
{
}
public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
{
}
}
解决方案
推荐阅读
- c++ - 使用带有 Power bi 的自定义 odbc 驱动程序
- django - Nginx 配置已经存在/文件丢失
- java - 如何在电子商务网站的后端存储图像?
- mongodb - MongoDB Aggregate - 如何让两个“$lookup”操作工作?
- jquery - .$ajax 在 SpringBoot SELECT 中不起作用。可以得到任何解决方案吗?
- python - 如何在我的 df 分析中显示策略
- javascript - 如何将网站上的元素与给定变量进行比较,并在 if 语句 *THAT WORKS* 中使用它?
- maven - 为什么在从 appcfg mvn 迁移到 gcloud 后,Java 8 GAE 项目不支持 Maven 源部署错误
- websphere-liberty - Liberty 中的端点启动通知
- javascript - 更改字体真棒按钮样式 onClick