系統(tǒng)語言為英文時,定位默認返回英文或拼音毙石,系統(tǒng)語言是中文時才返回中文匪凡。
需求: 強制系統(tǒng)獲取的定位地點為中文。
此技能適用于所有關于定位的方法中
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
// 獲取經緯度
NSLog(@"緯度:%f",newLocation.coordinate.latitude);
NSLog(@"經度:%f",newLocation.coordinate.longitude);
// 停止位置更新
[manager stopUpdatingLocation];
// 保存 Device 的現語言 (英語 法語 呵燕,儒士,,)
NSMutableArray *userDefaultLanguages = [[NSUserDefaults standardUserDefaults]
objectForKey:@"AppleLanguages"];
// 強制 成 簡體中文
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"zh-hans",nil]
forKey:@"AppleLanguages"];
// 逆地理編碼
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if(!error){
for (CLPlacemark * placemark in placemarks) {
NSString *cityName = [placemark locality];
NSLog(@"cityName===》%@", cityName);//這里可看到輸出為中文
break;
}
}
// 還原Device 的語言
[[NSUserDefaults standardUserDefaults] setObject:userDefaultLanguages forKey:@"AppleLanguages"];
}];
}