从越狱的iphone shell脚本中获取地理位置数据

时间:2012-12-14 05:05:32

标签: iphone ios ios5 geolocation jailbreak

我终于越狱了我的iPhone 4S(iOS 5.1.1)。我非常熟悉linux / windows编程(c / c ++)和shell脚本。我不熟悉XCode / Objective-C,我没有mac。

我想要一种简单的方法来跟踪我自己的地理位置,并每隔几分钟将经度/纬度(?准确度?)写入我的iPhone上的文本文件中。我不需要太多准确性。细胞塔方法应该工作正常,所以我不会终止电池寿命。

如果我可以获得一个只吐出lat / long的命令行应用程序,那么我相信我可以通过一些bash包装器脚本找出需要做什么才能将它变成“后台守护程序”类型应用程序。

我在Cydia找不到这样的应用程序。有一些会在社交网站上自动更新您的位置,但我想要这样做。我只想要一个本地日志,以便我可以将其scp到我的家庭服务器进行个人跟踪。 (我经营一家小企业,有时需要向客户证明我在他们所在的位置有多长时间)

1 个答案:

答案 0 :(得分:-1)

CoreLocation文档应该回答您的任何问题。但要获取手机的当前位置:

// based on http://www.icodeblog.com/tag/corelocation/
@interface CFAAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>

@property (strong, nonatomic) UIWindow *window;

//Add a location manager property to this app delegate
@property (strong, nonatomic) CLLocationManager *locationManager;

@end
@implementation CFAAppDelegate

@synthesize window = _window;
@synthesize locationManager=_locationManager;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    if(self.locationManager==nil){
        _locationManager=[[CLLocationManager alloc] init];
        //I'm using ARC with this project so no need to release

        _locationManager.delegate=self;
        _locationManager.purpose = @"We will try to tell you where you are if you get lost";
        _locationManager.desiredAccuracy=kCLLocationAccuracyBest; // other options exist, let's assume this one
        _locationManager.distanceFilter=500;
        self.locationManager=_locationManager;
    }

    return YES;
}
- (void)awakeFromNib {
  if([CLLocationManager locationServicesEnabled]){
        [self.locationManager startUpdatingLocation];
    }
}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
   NSDate* eventDate = newLocation.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    if (abs(howRecent) &lt; 15.0)
    {
            //Location seems pretty accurate, let's use it!
            NSLog(@"latitude %+.6f, longitude %+.6f\n",
                  newLocation.coordinate.latitude,
                  newLocation.coordinate.longitude);
    }

将其报告给数据存储区是一个留给读者的练习。