Размещение в UIWebView - iPhone
Привет, мне интересно, есть ли возможность отправить широту и длину местоположения людей на URL? Также необходимо иметь их номер UDID для сопоставления с базой данных.
Вот что у меня есть, если кто-нибудь может помочь, это было бы здорово...
-(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 ];
}
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]);
}