iPhone - のUIWebViewにcllocation
-
21-09-2019 - |
質問
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 ];
}
解決
あなたは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]);
}
所属していません StackOverflow