2011-09-05 145 views
1

嗨,我使用mkreversegeocoder找到用戶的當前city.It作品,但是當我在其他地方試試它給市鎮/地區的名稱在我的國家(土耳其)。例如它提供了「伊斯坦布爾」正確的,但有在我的國家沒有像「susurluk」這樣的城市名稱這是一個地區。任何想法爲什麼它返回我區而不是城市名?如果你想我會後我的代碼的MKReverseGeocoder返回不是城市的城市?

編輯1:

-(void)viewDidLoad { 
[super viewDidLoad]; 


manager=[[CLLocationManager alloc]init]; 
manager.delegate=self; 
manager.desiredAccuracy=kCLLocationAccuracyBest; 

[manager startUpdatingLocation]; 

} 

-(void)locationManager:(CLLocationManager *)aManager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 


    MKReverseGeocoder *geocoder=[[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate]; 
    geocoder.delegate=self; 
    [geocoder start]; 

    [manager startUpdatingLocation]; 

} 

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { 

NSDictionary * addressDict= [placemark addressDictionary]; 

//NSString *country = [addressDict objectForKey:@"Country"]; 

NSString *city = [addressDict objectForKey:@"City"]; 

//change the country name into en_US 

NSLocale *locale = [NSLocale currentLocale]; 
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode]; 

NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; 

NSString *country1 = [usLocale displayNameForKey: NSLocaleCountryCode value: countryCode]; 

[[NSUserDefaults standardUserDefaults] setObject:country1 forKey:@"country"]; 
[[NSUserDefaults standardUserDefaults] setObject:city forKey:@"city"]; 

[[NSUserDefaults standardUserDefaults] synchronize]; 

} 


-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { 

if (error.code == kCLErrorHeadingFailure) { 
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Problem" 
                message:@"Can't find the location!" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles: nil]; 

    [alertView show]; 
    [alertView release]; 
    [manager stopUpdatingLocation]; 
     } 

} 

-(void)locationManager:(CLLocationManager *)manager1 didFailWithError:(NSError *)error  { 

if (error.code != kCLErrorDenied) { 

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Problem" 
                 message:@"Can't find the location!" 
                 delegate:self 
               cancelButtonTitle:@"OK" 
               otherButtonTitles: nil]; 

    [alertView show]; 
    [alertView release]; 
    [manager stopUpdatingLocation]; 

    } 

} 
+0

在這種情況下,它的發生 – Srinivas

+0

當我在「巴勒克埃西爾」的城市和它的區「susurluk」我使用的應用程序,看看它susurluk返回我,而不是返回我「 balıkesir「。並在」balıkesir「多個地區。 –

+0

你在初始化時傳遞座標(lat/long)還是別的什麼, – Srinivas

回答

1

您可以通過使用您擁有谷歌地圖API的經/緯度送的地方得到正確的答案,你會以json/xml的形式獲得答案。請看看這個問題

Reverse Geocoding With Google Map API And PHP To Get Nearest Location Using Lat,Long coordinates

+0

感謝的答案,但我需要將它與PHP的連接?是iPhone的GPS不能單獨工作?找到它單獨工作位置 –

+0

,但你需要將由谷歌API.I給予答覆已經在使用它許多應用程序和他們都工作得很好。 – Ballu