2011-04-08 46 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 2011-04-08 00:54:18

+0

找到當前的天氣狀況並找到對城市名稱 – N15H4NJ0 2011-04-08 00:59:14

+0

沒有多大幫助。如果你在你的程序中硬編碼座標,爲什麼你不簡單地編碼城市名稱呢?另外,從來沒有達到其他條款,所以沒有wheather ... – hop 2011-04-08 01:07:35

回答

-1

嘗試緯度= 50.5,經度= 0

+0

如果他想在英國購買MKPlacemark,他可以簡單地創建一個。不需要用反向地理編碼來做愚蠢的舞蹈。 – hop 2011-04-08 00:56:28