2013-08-17 44 views
0
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(27.941761 , -82.171537); 

    MKReverseGeocoder *reverseGeocoder =[[MKReverseGeocoder alloc] initWithCoordinate:coordinate]; 
    NSLog(@"%g",coordinate.latitude); 
    NSLog(@"%g",coordinate.longitude); 
    reverseGeocoder.delegate = self; 
    [reverseGeocoder start]; 
//???????????????????????????????????????????????????????????????????????? 

} 

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ 
NSLog(@"MKReverseGeocoder has failed."); 
} 
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark   *)placemark{ 

NSLog(@"current place is :%@",placemark); 
} 

當我使用手寫座標時,reverseGeocoding失敗。但是當我使用 - 座標從(void)locationManager:(CLLocationManager *)管理器didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation成功。爲什麼?ios reverseGeocoder失敗,當我固定座標?

回答

1

當我放棄你的代碼放到一個測試項目,它的工作完美的罰款對我來說:

2013-08-16 23:45:55.966 TestMapApp[11261:a0b] 27.9418 
2013-08-16 23:45:55.967 TestMapApp[11261:a0b] -82.1715 
2013-08-16 23:45:57.831 TestMapApp[11261:a0b] current place is :6015 W Farkas And Turkey Creek Rd, Plant City, FL 33567, United States @ <+27.94176100,-82.17153700> +/- 0.00m 

這是我覺得是走錯了。您正在使用ARC,並且不會在任何地方(例如在伊娃或財產中)儲存「reverseGeocoder」,因此只要您創建「reverseGeocoder」的功能完成,ARC就會發布它。

一對夫婦的其他東西:

如果在委託方法提供給你一個錯誤的參數,你應該使他們的使用。就像這樣:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ 
    NSLog(@"MKReverseGeocoder has failed with error %@.", [error localizedDescription]); 
} 

而且最後&最重要的是,「MKReverseGeocoder」已經過時了,因爲iOS的5有一個很好的機會,它會在iOS中的未來版本中消失。您應該嘗試找到用於反向地理編碼的替代品。