1

Hi i am using mkreversegeocoder to find the users current city.It works but when i try it in another location it gives the names of borough/district in my country (Turkey).For example it gives "istanbul" correct but there is no city name like "susurluk" in my country it is a district.Any idea why it returns me districts instead of city name? if you want i would post my code's

edit 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];

  }

}
diatrevolo
  • 2,782
  • 26
  • 45
john doe
  • 177
  • 1
  • 4
  • 13
  • when i am at "balıkesir" the city and its district "susurluk" i use the app to see and it returns me susurluk instead of returning me "balıkesir".And a couple of more districts in "balıkesir". – john doe Sep 05 '11 at 09:11
  • what your doing by passing Coordinates(lat/long ) while initializing or something else; – Srinivas Sep 05 '11 at 09:24
  • you can check my codes i didnt understand what u mean sorry :( – john doe Sep 05 '11 at 09:29
  • now i am getting "Istanbul Province" returns right place. – john doe Sep 05 '11 at 10:50
  • I hope MKReverseGeocoder takes SomeTime 23 Sec To Find Place Mark Before That If UpDate Location Its Not initlizing Properly Or you try To stop Updating Location When find Location In Update Did Location Manager – Srinivas Sep 05 '11 at 11:00
  • well this is my all code if there isn't any error return to me i never stop updating location.now i made it to update every 30 sec. – john doe Sep 05 '11 at 11:17
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/3168/discussion-between-srinivas-and-john-doe) – Srinivas Sep 05 '11 at 11:27

1 Answers1

1

You can get the correct answer by using the google map api in which you have to send the lat/long of the place and you will get answer in the form of json/xml. Please check out this question

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

Community
  • 1
  • 1
B25Dec
  • 2,301
  • 5
  • 31
  • 54
  • thanks for the answer but do i need to connect it with php ? is iphone gps doesn't work alone? to find the location – john doe Sep 05 '11 at 09:45
  • IT work alone, but the answer you need that will be given by the google API.I have used it in many apps and all they are working fine. – B25Dec Sep 06 '11 at 06:17