2011-09-05 58 views
0
讀取GPS聯合ORDS

我有我的主要.m文件下面的代碼(我想送一個HTTP查詢字符串中的GPS共同ORDS)iPhone SDK,從的LocationManager

- (CLLocationManager *)locationManager { 

    if (locationManager != nil) { 
     return locationManager; 
    } 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 

    return locationManager; 
} 


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *) oldLocation { 


    NSString *latitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.latitude]; 
    NSLog(@"lat is %@", latitudeString); 
    //self.myLatitude = latitudeString; 
    [latitudeString release]; 

    NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.longitude]; 
    NSLog(@"long is %@", longitudeString); 
    //self.myLongitude = longitudeString; 
    [longitudeString release]; 

} 

而且在我的.h我:

@interface RootViewController : UITableViewController {  

    CLLocationManager *locationManager; 

} 

@property (nonatomic, retain) CLLocationManager *locationManager; 


@end 

(我已經剝離出來的.H不必要的行)

我怎樣才能在代碼不同的塊使用當前GPS經度/緯度從上面:(代替LONGVAR/LATVAR)

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *tempvariable; 
    NSString *gpsLat; 



    switch (indexPath.row) { 

     case 0: 
      tempvariable = @"http://randomurl.randomurl.com/mobilesearch/what/Hotels%20and%20Inns/0/0/0/UK/**LONGVAR/LATVAR**/0/0/342/0/0/0/0/0/search.aspx"; 
      break; 
     case 1: 
      tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/Public%20Houses/0/0/0/UK/**LONGVAR/LATVAR**/0/0/505/0/0/0/0/0/search.aspx"); 
      break; 
     case 2: 
      tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/All%20Restaurants/0/0/0/UK/**LONGVAR/LATVAR**/0/0/527/0/0/0/0/0/search.aspx"); 
      break; 
     case 3: 
      tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/Health Care/0/0/0/UK/**LONGVAR/LATVAR**/0/0/843/0/0/0/0/0/search.aspx"); 
      break; 
     default: 
      tempvariable = (@"http://randomurl.randomurl.com/mobilesearch/what/Hotels and Inns/0/0/0/UK/**LONGVAR/LATVAR/**0/0/342/0/0/0/0/0/search.aspx"); 
      break; 
    } 
} 

回答

0

,也許我失去了一些東西,但只是存儲在newLocation.coordinate.latitude您在頭定義了一些浮點值..

你可以有一個singletone類,如果你需要在整個應用程序,或將其存儲到nsuserdefaults ..

+0

嗨@paxx謝謝你。我做了嘗試,我在頭 'CLLocationDegrees * gpsLat過這樣的;' 並在此類: 'gpsLat = newLocation.coordinate.latitude;' 但我得到一個錯誤約asigning一個CLLocationDegrees到CLLocationDegrees – TMB87

+0

只是從CLLocationDegrees中刪除*。像這樣做'CLLocationDegrees gpsLat'。這應該是。不使用*的原因是因爲CLLocationDegrees是一個結構而不是對象。你可以使用cmd鍵+雙擊一個變量,它會引導你定義。 – paxx

+0

謝謝你,我已經設置了變量(據我所知),但它沒有發送它,我怎麼調用例程運行,因爲顯然沒有設置' - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {'在viewDidLoad中,還是自動運行? – TMB87