0

我正在考虑使用 GEO 提醒的应用程序(在 iOS5 中添加的那些,在我离开/到达时在某个位置提醒我)。但我需要使用此功能(实际上,仅使用位置)来获取当前位置并将其与我的应用程序定义的位置进行比较,并检查它是否相同。如果当前位置和定义的位置相同,请启动我的应用程序。

这可能吗?

我希望你能理解我的目的。提前致谢

4

3 回答 3

1

当您设置要监控的区域时,会自动检查当前区域和已定义区域。最好的起点是阅读文档CLLocationManagerDelegate,尤其是startMonitoringForRegion:. 你想做的事情叫做“地理围栏”。您还可以在位置感知指南中找到更多信息。

于 2012-07-28T01:14:01.413 回答
1

虽然您将能够从后台监控您的位置,但请记住,它不会自动启动您的应用程序。您可以使用诸如本地通知之类的东西来提示用户打开应用程序。但是从后台自动启动不是一种选择。至少不是 App Store 批准的选项。

于 2012-07-28T01:24:05.427 回答
0

作为 iPhone 开发的新手,我不知道如何以编程方式为应用程序提供午餐,但我可以帮助您解决到达预定义位置的触发器。这是代码。

1:导入CoreLocation.framework

2:在 viewController.h 文件中放置以下代码

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
@end

3:inviewController.m

#import "ViewController.h"
@interface ViewController (){
CLLocationManager *locationManager;
CLRegion *mexicoBoundary;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
   [super viewDidLoad];

locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];



CLLocationCoordinate2D regionCords ;
//19.432608,-99.133208 lat, lon for mexico city
regionCords=CLLocationCoordinate2DMake(19.432608,-99.133208);
//5000 below, is in meters-radius 
mexicoBoundary =
[[CLRegion alloc]initCircularRegionWithCenter:regionCords
                                       radius:5000.0
                                   identifier:@"mexico_Day"];

[locationManager startMonitoringForRegion:mexicoBoundary];

}

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"%@: %@", @"region entered", region.identifier);

}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"%@: %@", @"region exited", region.identifier);
}



- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

@end
于 2013-02-20T13:02:15.257 回答