2010-02-17 45 views
0

嗨,我想知道是否有離開發送一個人的位置經緯度和長期的URL?它還需要使其UDID號碼與數據庫匹配。cllocation to UIWebView - iPhone

這裏是我到目前爲止,如果有人能夠幫助這將是偉大的...

-(void)viewDidLoad {  
    NSString *query = [[NSString alloc] initWithFormat: 
          @"http://mysite.com/ihome.php?uid=%@", 
          [[UIDevice currentDevice] uniqueIdentifier], 
          @"&year=2010%@"]; 
    NSURL *url = [[NSURL alloc] initWithString:query]; 
    NSURLRequest *requestObj = [ NSURLRequest requestWithURL: url ]; 
    webView.opaque = NO; 
    webView.backgroundColor = [UIColor clearColor]; 
    [webView loadRequest: requestObj ]; 
} 

回答

0

你必須計算經度和緯度之前請求的URL。

- (void) viewDidLoad { 
    self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
    self.locationManager.delegate = self; // send location updates to this object 
    [self.locationManager startUpdatingLocation]; 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    NSLog(@"Your location: %@", [newLocation description]); 

    NSString *query = [[NSString alloc] initWithFormat: 
          @"http://mysite.com/ihome.php?uid=%@&longitude=%d&latitude=%d", 
          [[UIDevice currentDevice] uniqueIdentifier], 
          @"&year=2010%@", 
          newLocation.longitude, 
          newLocation.latitude]; 
    NSURL *url = [[NSURL alloc] initWithString:query]; 
    NSURLRequest *requestObj = [ NSURLRequest requestWithURL: url ]; 
    webView.opaque = NO; 
    webView.backgroundColor = [UIColor clearColor]; 
    [webView loadRequest: requestObj ]; 

} 

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
    NSLog(@"Error: %@", [error description]); 
} 
+0

我得到的錯誤說/Users/russellharrower/Documents/iPhone/QH/WebViewController.m:18:0 /Users/russellharrower/Documents/iPhone/QH/WebViewController.m:18:錯誤:請求成員在東西 '的LocationManager' 不是一個結構或聯合 和四肢其他錯誤 在我的.h文件,我有這個 #進口 #進口 @interface WebViewController:UIViewController IBOutlet UIWebView * webView; } @property(nonatomic,retain)UIWebView * webView; @end 我錯過了什麼嗎?我的m文件有你添加的上面的代碼。 – RussellHarrower 2010-02-18 01:22:59

+0

現在我只有兩個錯誤 - 錯誤:請求成員的'經度'在一些不是結構或工會 錯誤:請求成員'緯度'的東西不是結構或工會 – RussellHarrower 2010-02-18 01:33:57

+0

對不起,我犯了一個錯誤。在NSString *查詢之前,使用它: CLLocation * location = [locationManager location]; \t if(!location){ \t \t return; \t} \t \t CLLocationCoordinate2D coordinate = [location coordinate]; 然後使用coordonate.longitude和coordonate.latitude代替newLocation.longitude或緯度。 – 2010-02-18 08:11:56