2011-04-08 2 views
0

아래 코드는 미국의 위치를 ​​알려줍니다. 동일한 코드 도움말을 사용하여 영국 위치를 어떻게 찾을 수 있습니까?iPhone 앱의 위치 문제

#import "LocalWeatherViewController.h" 
#import "ICB_WeatherConditions.h" 
#import "MapKit/MapKit.h" 

@implementation LocalWeatherViewController 

@synthesize currentTempLabel, highTempLabel, lowTempLabel, conditionsLabel, cityLabel; 
@synthesize conditionsImageView; 
@synthesize conditionsImage; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    if (1) 

     { 

     CLLocationCoordinate2D coord; 
     coord.latitude = 45.574779; 
     coord.longitude = -122.685366; 


     MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coord]; 
     geocoder.delegate = self; 
     [geocoder start]; 
    } 
    else 
    { 

     [self performSelectorInBackground:@selector(showWeatherFor:) withObject:@"97217"]; 
    } 
} 

- (void)showWeatherFor:(NSString *)query 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

    ICB_WeatherConditions *weather = [[ICB_WeatherConditions alloc] initWithQuery:query]; 

    [self.currentTempLabel setText:[NSString stringWithFormat:@"%d", weather.currentTemp]]; 
    [self.highTempLabel setText:[NSString stringWithFormat:@"%d", weather.highTemp]]; 
    [self.lowTempLabel setText:[NSString stringWithFormat:@"%d", weather.lowTemp]]; 
    [self.conditionsLabel setText:weather.condition]; 
    [self.cityLabel setText:weather.location]; 

    self.conditionsImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:weather.conditionImageURL]]; 

    [weather release]; 

    [pool release]; 
} 


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    [geocoder release]; 
    [self performSelectorInBackground:@selector(showWeatherFor:) withObject: [placemark.addressDictionary objectForKey:@"ZIP"]]; 
} 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error 
{ 
    NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error); 
    [geocoder release]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

- (void)viewDidUnload { 

} 

- (void)dealloc { 
    [super dealloc]; 
} 

@end 
+0

당신이 실제로 원하는 것을 파악하기가 매우 어렵다. 질문을 더 명확하게 말하십시오. – hop

+0

현재의 기상 조건을 찾고, 도울 수없는 도시 이름 – N15H4NJ0

+0

을 찾아야합니다. 프로그램에서 좌표를 하드 코딩하면 도시 이름을 간단히 하드 코딩하면됩니까? 또한 else 절은 절대로 도달하지 않으므로 아무런 문제가 없습니다. – hop

답변

-1

시도 위도 = 50.5, 경도 = 0

+0

영국에서 MKPlacemark가 필요한 경우 간단하게 만들 수 있습니다. 역 지오 코딩으로 어리석은 춤을 추릴 필요가 없습니다. – hop