2010-02-17 82 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