سؤال

أتساءل عما إذا كان هناك بعيدا لإرسال اللاتة وطول موقع الشخص إلى عنوان 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]);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top