xamarin - 如何使用 xamarin 在 Google 地图上每 x 秒刷新/更新 pin 位置
问题描述
我正在开发基于 xamarin 的移动应用程序。我需要从服务器检索有关用户位置的数据,并每 x 秒更新一次地图上的用户位置。我在服务器上存储用户纬度和经度,但是当我从服务器检索坐标时是最新的大头针不会在地图上渲染。只有第一次渲染大头针时,即使纬度和经度的位置发生变化,大头针也会保持原样,不会在新位置渲染。有人可以提供相同的解决方案吗?
请在下面找到代码 这段代码用于每 10 秒获取一次位置
Device.StartTimer(TimeSpan.FromSeconds(10), () =>
{
bool CallAgain = true;
lblStatus.IsVisible = false;
mapVM.getGpsPosition().ContinueWith((Task<ApiResponseModel.DriverLocationDetailsResponseModel> t) =>
{
if (t.Result.status == DriverStatus.Running.ToString() || t.Result.status == DriverStatus.Started.ToString())
{
RedrawMap(t.Result.lat, t.Result.lon);
}
else
{
ParentMaps.IsVisible = false;
lblStatus.IsVisible = true;
lblStatus.Text = "Driver has stopped the journey";
CallAgain = false;
}
});
return CallAgain;
});
这段代码用于在地图上绘制图钉
private void RedrawMap(double lat, double lon)
{
var pin = new CustomPin
{
Type = PinType.Place,
Position = new Xamarin.Forms.Maps.Position(lat, lon),
Label = "Current Location",
Id = "Xamarin"
};
DriverMap.CustomPins = new List<CustomPin> { pin };
if (DriverMap.Pins.Count > 0)
{
DriverMap.Pins.Clear();
}
DriverMap.Pins.Add(pin);
DriverMap.MoveToRegion(
MapSpan.FromCenterAndRadius(new
Xamarin.Forms.Maps.Position(lat, lon),
Distance.FromMiles(0.1))
);
}
解决方案
你可以做一个计时器,每 x 秒清理一次引脚并重新加载新引脚
参考:https://forums.xamarin.com/discussion/118999/refresh-pins-positions-in-google-maps
推荐阅读
- python - 如何使用python从大文件中删除特定行?
- django - 在 Django 中将多条记录作为一条读取
- python - 在 matplotlb 上绘制带有 2 个辅助轴变量的组合图
- node.js - 如何使用 PDFKit 将谷歌地图集成到 pdf 中
- java - 使用来自 java 的 maven 原型
- asynchronous - 异步完成()在 moch-chai 中不起作用。无法访问 http 响应
- sql-server - 从 Flutter Desktop for Windows 访问 SQL Server
- sql - 如何将多个文件(相同架构)从 LOCAL 加载到 BigQuery 中的表中?
- java - 有没有办法获得国家 ISO-2 代码,但从 Windows 属性,而不是从 JVM
- react-native - stacknavigator react native set title of top menu