Detect if user enters or leaves a region - geocoding

不羁的心 提交于 2019-12-08 12:15:17

问题


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.


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/8819678/detect-if-user-enters-or-leaves-a-region-geocoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!