2010-02-17 9 views
0

cllocation 안녕하세요, URL에 사람 위치의 위도와 경도를 보낼 거리가 있는지 궁금합니다. 또한 UDID 번호가 데이터베이스와 일치해야합니다. 여기 UIWebView - iPhone

는 ... 내가 지금까지 사람이 그 좋은 것 도울 수 있다면 무엇을 당신은 URL을 요청하기 전에 경도와 위도를 계산해야

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

답변

0

입니다.

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

내가 얻을 오류가 /Users/russellharrower/Documents/iPhone/QH/WebViewController.m:18:0 /Users/russellharrower/Documents/iPhone/QH/WebViewController.m:18 말 : 오류 : 멤버에 대한 요청 내 .H 파일에서 뭔가 '을 locationManager'가 아닌 구조 또는 노동 조합 과 발로 기타 오류 나는이 # import를 # import를 @ 인터페이스가 WebViewController : UIViewController { \t IBOutlet UIWebView * webView; } @property (비 원자력, 유지) UIWebView * webView; @end 내가 놓친 것이 있습니까? 내 m 파일에 위의 코드가 추가되었습니다. – RussellHarrower

+0

이제 두 가지 오류 만 있습니다. 오류 : 구조체 또는 공용체가 아닌 무언가에서 '경도'를 요청하십시오. 오류 : 구조체 또는 공용체가 아닌 무언가에 '위도'멤버가 요청되었습니다. – RussellHarrower

+0

아, 죄송합니다. . 는 NSString * 쿼리 전에 사용 CLLocation * 위치 = 위치을 locationManager]; \t 경우 (위치!) { \t \t 반환; \t} \t \t CLLocationCoordinate2D 좌표 = [위치 좌표]; 그리고는 coordonate.longitude 사용하고 대신 newLocation.longitude 또는 위도의 coordonate.latitude. –

관련 문제