我创建了一个 xamarin 移动应用程序,并希望创建以下功能:创建一个或多个地理围栏。当带电话的用户在该位置时,我想触发一些代码。是否有任何库可用于通过 xamarin 表单实现此跨平台?
如果您的地理围栏是圆形,则可以使用Xamarin.Essentials获取2 点之间的距离,如果距离小于地理围栏距离,则它在地理围栏内。
long geofenceDistance = 2;
Location geofenceCentercordinate = new Location(centrerCoordinate.Latitude, centrerCoordinate.Longitude);
Location userLocation = new Location(position.Latitude, position.Longitude);
var distance = (long)Location.CalculateDistance(userLocation ,geofenceCentercordinate, DistanceUnits.Kilometers);
if(distance < geofenceDistance){
//it's inside the Geofence
}
此外,如果您想持续监听您的位置,您可以在此处查看我的其他 anwser 。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句