2012-12-14 127 views
0

我终于jailbroke我的iPhone 4S(iOS 5.1.1)。我非常熟悉linux/windows编程(c/C++)和shell脚本。我不熟悉XCode/Objective-C,我没有一个mac。从越狱iphone外壳脚本获取地理位置数据

我想要一个简单的方法来追踪我自己的地理位置,并且每隔几分钟将经度/纬度(?精度?)写入我的iPhone上的文本文件。我不需要太多的准确性。细胞塔法应该工作得很好,所以我不会杀死我的电池寿命。

如果我能得到一个刚刚吐出经纬度的命令行应用程序,我相信我可以通过一些bash包装脚本找出需要做些什么来将它变成“后台守护进程”类型的应用程序。

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

回答

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

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

+0

他将在越狱设备上部署。对于shell脚本,使用python Cocoa-touch绑定可能更方便。 – ZhangChn

+0

这是一个通用的解决方案,也适用于非越狱设备,如我的。 – hd1

+0

不幸的是,这个问题基本上是要求在Objective-C中没有编码的情况下做到这一点,所以我怀疑这对他有多大帮助。 – Nate