Detect if user enters or leaves a region - geocodi

2019-06-12 03:26发布

I'm starting with geocoding. And I have a lot of doubts.

I'm able to do forward and reverse geocoding (I guess, its not perfect).

And now, I'm trying to detect if user (device) enters or leaves a region. For that, I picked up apple's sample code "Regions". The sample uses regionMonitoring. I already try it in a device, but its not working well. I set a region with 25 meters radius, and when I left the region (walking) doesn't happen anything.

My question is: there is another and better way of doing this, detect if user enters or leaves a region, than regionMonitoring?

Can someone help me here??

Thanks a lot.

2条回答
Summer. ? 凉城
2楼-- · 2019-06-12 04:04

I found a solution to calculate the distance between two CLLocationCoordinate2D it is easier than I though:

- (CLLocationDistance) DistanceBetweenCoordinate:(CLLocationCoordinate2D)originCoordinate andCoordinate:(CLLocationCoordinate2D)destinationCoordinate {

    CLLocation *originLocation = [[CLLocation alloc] initWithLatitude:originCoordinate.latitude longitude:originCoordinate.longitude];
    CLLocation *destinationLocation = [[CLLocation alloc] initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
    CLLocationDistance distance = [originLocation distanceFromLocation:destinationLocation];
    [originLocation release];
    [destinationLocation release];

    return distance;
}
查看更多
Root(大扎)
3楼-- · 2019-06-12 04:08

you could keep the user-location tracking running in the background (here is a good tutorial) but keep in mind this can be heavier on battery use than regionMonitoring.

查看更多
登录 后发表回答