如何正确设置CLRegion的半径? [英] How to properly set the Radius of CLRegion?

查看:143
本文介绍了如何正确设置CLRegion的半径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我创建地理围栏的代码:

  Geofence * geofence = [[Geofence alloc] init]; 
[geofence setRadius:100.0];
[geofence setIdentifier:@ Fence1];
[geofence setLocation:currentlocation];


CLRegion * region1 = [[CLCircularRegion alloc] initWithCenter:[geofence.location坐标]
radius:geofence.radius
标识符:geofence.identifier];

region1.notifyOnEntry = YES;
region1.notifyOnExit = YES;
[self.locationManager startMonitoringForRegion:region1];

我可以说上面的代码有效,这意味着地理围栏已经创建。但是我遇到了一个问题。



我有一个.gpx文件(将在其中模拟我的当前位置),它们到区域中心/地理区域的距离如下: 55m,90m,150m,200m,300m,500m,1Km,5Km和10Km。



我的问题是,看来我的地理围栏半径并不是真正的100m,因为当我模拟使用距地理围栏中心距离为55m,90m,150、200m,300m,500m,1km的gpx文件。 LocationManager -didEnterRegion -didExitRegion 的委托方法做出的响应是我位于我的Geofence中,其半径为只是 100m。



只有距我的地理围栏中心的距离为5Km和10km的gpx文件会响应我在地理围栏之外的上述委托方法。 / p>

您能帮我解决这种情况吗?



解决方案

我认为问题可能在于,您使用与初始化地理围栏相同的变量来初始化您的区域就其中心坐标而言。因此,一个人总是在另一个人内部思考它。


This is my code for creating a geofence:

Geofence *geofence = [[Geofence alloc] init];
[geofence setRadius:100.0];
[geofence setIdentifier: @"Fence1"];
[geofence setLocation:currentlocation];


CLRegion *region1 =  [[CLCircularRegion alloc] initWithCenter:[geofence.location coordinate]
                                               radius:geofence.radius
                                               identifier:geofence.identifier];

region1.notifyOnEntry=YES;
region1.notifyOnExit=YES;
[self.locationManager startMonitoringForRegion:region1];

I could say that, the above code works, meaning the geofence have been created. But there's a problem I've been encountering.

I have a .gpx files (in which I will be using for simulation of my current location), their distances from the center of the region/geofence are as follows: 55m, 90m, 150m, 200m, 300m, 500m, 1Km, 5Km and 10Km.

My problem is, its seems that my geofence radius is not really 100m, because when I simulate using gpx files whose distance from the center of the geofence are 55m, 90m, 150, 200m, 300m, 500m, 1km. The delegate methods of LocationManager -didEnterRegion and -didExitRegion is making a respond that I'm within my Geofence whose radius is just "100m".

Only the gpx files with distances from my geofence center that are 5Km and 10km responds from the said delegate methods that I'm outside the Geofence.

Can you help me resolve this scenario guys?

解决方案

I think the problem may be that you are using the same variables to initialize your region with as the ones you are using to initialize your geofence as far as their center coordinates are concerned. Thus one always thinks its within the other.

这篇关于如何正确设置CLRegion的半径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆