美文网首页
强制系统获取的定位地点为中文

强制系统获取的定位地点为中文

作者: 默默学习 | 来源:发表于2017-02-06 17:34 被阅读89次

    系统语言为英文时,定位默认返回英文或拼音,系统语言是中文时才返回中文。

    需求: 强制系统获取的定位地点为中文。

    此技能适用于所有关于定位的方法中

    -(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"];
        }];
    }
    

    相关文章

      网友评论

          本文标题:强制系统获取的定位地点为中文

          本文链接:https://www.haomeiwen.com/subject/dhsuittx.html