UIWebView 的位置 - iPhone

发布于 2024-08-22 02:39:35 字数 620 浏览 10 评论 0原文

我想知道是否可以将一个人的位置的经纬度发送到 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 ];
}

I am wondering if there is away to send the lat and long of a person's location to a URL? It would also need to have their UDID number to match with the database.

Here is what I have so far:

-(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 ];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜灵血窟げ 2024-08-29 02:39:35

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

You have to calculate the longitude and the latitude before to request the 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]);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文