【问题标题】:cllocation to UIWebView - iPhone配置到 UIWebView - iPhone
【发布时间】:2010-02-17 16:46:08
【问题描述】:

我想知道是否可以将一个人的位置的经纬度发送到 URL?它还需要具有与数据库匹配的 UDID 编号。

这是我目前所拥有的:

-(void)viewDidLoad {    
     NSString *query = [[NSString alloc] initWithFormat:
                          @"http://example.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 ];
}

【问题讨论】:

    标签: iphone uiwebview cllocation


    【解决方案1】:

    在请求 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]);
    }
    

    【讨论】:

    • 我收到错误说 /Users/russellharrower/Documents/iPhone/QH/WebViewController.m:18:0 /Users/russellharrower/Documents/iPhone/QH/WebViewController.m:18: error: request对于不是结构或联合的成员“locationManager”以及其他错误在我的 .h 文件中我有这个 #import #import @interface WebViewController : UIViewController { IBOutlet UIWebView *网络视图; @property (nonatomic, 保留) UIWebView *webView; @end 我错过了什么吗?我的 m 文件有上面你添加的代码。
    • 现在我只有两个错误 - 错误:请求非结构或联合的成员“经度”错误:请求非结构或联合的成员“纬度”
    • 对不起,我犯了一个错误。在 NSString *query 之前,使用它: CLLocation *location = [locationManager location];如果(!位置){返回; } CLLocationCoordinate2D 坐标 = [位置坐标];然后使用 coordonate.longitude 和 coordonate.latitude 代替 newLocation.longitude 或 latitude。
    猜你喜欢
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多