2011-09-05 107 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