本文重点:
通过经纬度进行判断。利用高德SDK进行判断。(
如果是手动输入位置信息就进行逆地理编码获取经纬度再进行判断
)
用户没有选择是否要使用定位服务(弹框没选择,或者根本没有弹框)
[AMapLocationKit] 要在iOS 11及以上版本使用后台定位服务, 需要实现amapLocationManager:doRequireLocationAuth: 代理方法】
原理:根据经纬度判断是否在大陆地区
/**
根据经纬度判断 是否在大陆地区
*/
+ (BOOL)inChineseMainlandWithCLLocation:(CLLocation *)location regeocode:(AMapLocationReGeocode *)regeocode{
if(AMapLocationDataAvailableForCoordinate(location.coordinate)){//当前位置在大陆、港澳地区
//香港特别行政区
// 澳门特别行政区
/////省/直辖市
// @property (nonatomic, copy) NSString *province;
if([regeocode.province isEqualToString:@"香港特别行政区"] || [regeocode.province isEqualToString:@"澳门特别行政区"]){
return NO;
}else{
return YES;
}
}else{//其他地区
return NO;
}
return YES;
}
用法
CLLocation *location = [[CLLocation alloc]initWithLatitude:[array.lastObject doubleValue] longitude:[array.firstObject doubleValue]];
AMapLocationReGeocode* regeocode = [AMapLocationReGeocode mj_objectWithKeyValues:geocodesDto.mj_keyValues];
if([ERPAMapLocationTool inChineseMainlandWithCLLocation:location regeocode:regeocode]){
}else{
[SVProgressHUD showInfoWithStatus:@"您最新定位不在支持范围内!"];
return;
}
[weakSelf locotionRequestLat:[NSNumber numberWithDouble:location.coordinate.latitude].description Lon:[NSNumber numberWithDouble:location.coordinate.longitude].description adress:weakSelf.locationView.adressTextView.text];
大_陆
例如:116.480881,39.989410 转换地址描述后:北京市朝阳区阜通东大街6号
1、 请求
https://restapi.amap.com/v3/geocode/geo
把用户输入的经营地址位置信息转为经纬度信息 2、根据获取的经纬度信息再进行判断是否在大陆
/**
通过逆地理编码进行判断是否在大陆
*/
- (void)setupGeocode{
__weak __typeof__(self) weakSelf = self;
if (weakSelf.locationView.adressTextView.text.length > 0) {//1、 判断经营地址信息,不为空进行逆地理编码(请求`https://restapi.amap.com/v3/geocode/geo`把用户输入的经营地址位置信息转为经纬度信息)
[SVProgressHUD showWithStatus:@"定位中.."];
AFHTTPSessionManager *managers = [AFHTTPSessionManager manager];
managers.requestSerializer = [AFHTTPRequestSerializer serializer];
managers.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json",@"text/javascript",nil];
// 完成代码请看原文:https://kunnan.blog.csdn.net/article/details/119685526
}
完整代码请看原文:https://kunnan.blog.csdn.net/article/details/119685526
安装命令行工具代码:xcode-select --install
自签命令代码:codesign -f -s - --deep /Applications/i4Tools.app
在这里插入图片描述
在这里插入图片描述
// province=香港特别行政区
latitude=22.26429541107516
longitude=114.18135238995905
// province=澳门特别行政区
latitude=22.135584619138957
longitude=113.57214697205735
2020-04-09 15:39:54.504424+0800 retail[8369:4238323] reGeocode:AMapLocationReGeocode:{formattedAddress:澳门特别行政区圣方济各堂区靠近澳门青年挑战营; country:中国;province:澳门特别行政区; city:(null); district:圣方济各堂区; citycode:1853; adcode:820008; street:(null); number:(null); POIName:澳门青年挑战营; AOIName:(null);}
121.524582,25.028822
2020-04-09 16:02:47.411507+0800 retail[8369:4238323] reGeocode:AMapLocationReGeocode:{formattedAddress:台湾省(私)私立七田真超右脑教育托儿所; country:中国;province:台湾省; city:(null); district:(null); citycode:1886; adcode:710000; street:(null); number:(null); POIName:(私)私立七田真超右脑教育托儿所; AOIName:(null);}
【获取更多经纬度数据:https://lbs.amap.com/console/show/picker】
iOS测试技巧:通过GPX文件修改经纬度信息(模拟iOS设备的位置)
测试方法:先设置【使用app时允许】,再去系统的设置修改定位信息的权限为:【下次询问】。回到app去更新定位信息。
amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager*)locationManager
,来让用户进行选择。- (void)amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager*)locationManager
{
[locationManager requestAlwaysAuthorization];
}
在这里插入图片描述
iOS定位、地理/逆地理编码的使用:https://kunnan.blog.csdn.net/article/details/119685612
说起安全,这里先提醒下大家
近日一蠕虫病毒incaseformat将于
1月23日
再次爆发,该病毒伪装为文件夹图标,隐藏自身exe后缀骗取用户双击运行,发作时在C盘中生成ttry.exe或tsay.exe文件,可能删除C盘等系统盘以外所有盘符内文件,危害极大。即使该病毒诞生时间久远,现有专业杀毒软件均能可靠查杀。大家也要保持良好的操作习惯:不在陌生网站下载资源,不访问不可靠的网站,不使用陌生U盘,减少移动存储介质的使用频率
。