2012-12-14 57 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