美文网首页
开发问题笔记

开发问题笔记

作者: Kevin_wzx | 来源:发表于2020-11-19 10:34 被阅读0次

    目录

    1.iOS手机号码校验

    1.iOS手机号码校验

    下面代码方法有判断号段;有些需要具体判断大陆、港澳地区参考帮邦行司机端代码
    https://www.cnblogs.com/guozhihe/p/12923555.html

    //手机号码校验
    +(BOOL)verifyPhoneNumber:(NSString*)phone;
    
    //手机号码校验
    +(BOOL)verifyPhoneNumber:(NSString*)phone{
        
        phone = [phone stringByReplacingOccurrencesOfString:@" " withString:@""];
        if (phone.length != 11){
            return NO;
        }else{
            //130-199 11位
            NSString * NUM = @"^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-35-8]|8[0-9]|9[189])\\d{8}$";//有判断号段
            //NSString * NUM = @"^((1[3-9][0-9]))\\d{8}$";只判断长度格式不需要号段的用这个
            NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", NUM];
            BOOL isMatch = [pred evaluateWithObject:phone];
            
            if (isMatch) {
                return YES;
            }else{
                return NO;
            }
        }
    }
    

    2.关于使用NSURL *url = [NSURL URLWithString:String];url为空的问题

    NSURL *url = [NSURL URLWithString:String];一直返回为空,这是有的链接需要转换一下utf8才能正常加载,有的不需要转换直接可以加载,所以一起直接转换再加载比较稳妥。
    urlString = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlString];

    将url进行UTF8转换-正常加载

    3.百度地图根据经纬度进行逆编码

    地理编码指的是将地址信息建立空间坐标关系的过程,又可分为正向地理编码和反向地理编码。

    • 正向地理编码指的是由地址信息转换为坐标点的过程。该功能适用于根据用户输入的地址确认用户具体位置的场景,常用于配送人员根据用户输入的具体地址找地点。
    • 反向地理编码服务实现了将地址坐标转换为标准地址的过程。反向地理编码提供了坐标定位引擎,帮助用户通过地面某个地物的坐标值来反向查询得到该地物所在的行政区划、所处街道、以及最匹配的标准地址信息。通过丰富的标准地址库中的数据,可帮助用户在进行移动端查询、商业分析、规划分析等领域创造无限价值。

    相关链接:
    https://blog.csdn.net/wjchao1990/article/details/51727669
    https://xiaozhuanlan.com/topic/4968730251
    https://blog.csdn.net/nameis2541748437/article/details/49766105
    https://www.cnblogs.com/guitarandcode/p/5783805.html(CLPlacemark属性)

    demo:

    起终点模型里面的经纬度属性:
    @property (nonatomic,assign) CGFloat lng;
    @property (nonatomic,assign) CGFloat lat;
    
    当前页面VC里面的属性:
    @property (nonatomic, strong) BMKGeoCodeSearch *search;//逆编码
    @property (nonatomic, strong) BMKGeoCodeSearch *searchTwo;
    @property (nonatomic, copy) NSString *adCode;//城市编码(城市的区id)
    @property (nonatomic, copy) NSString *adCodeTwo;
    
    遵循协议:<BMKGeoCodeSearchDelegate>
    
    - (SKOrderElement *)orderElement {
        SKOrderElement *element = [[SKOrderElement alloc] init];
        element.start = self.startAddress.toElementsAddress;
        element.start.phone = self.phoneNum;
        element.start.name = isNullString(self.contactName) ? @"本人" : self.contactName;
        element.end = self.endAddress.toElementsAddress;
        if (self.curOrderType == OrderType_Carpool) {
            element.count = self.peopleNumber;
        } else {
            element.count = 1;
        }
        
        // 起终点坐标转化增加位置参数
        CGFloat startLat = element.start.location.lat;//起点坐标
        CGFloat startLng = element.start.location.lng;//终点坐标
        CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:startLat longitude:startLng];
        self.search = [[BMKGeoCodeSearch alloc] init];
        self.search.delegate = self;
        BMKReverseGeoCodeSearchOption *reverseGeoCodeOption = [[BMKReverseGeoCodeSearchOption alloc]init];
        reverseGeoCodeOption.location = startLocation.coordinate;
        reverseGeoCodeOption.isLatestAdmin = YES;//是否访问最新版行政区划数据(仅对中国数据生效)
        BOOL flag = [self.search reverseGeoCode: reverseGeoCodeOption];
        if (flag) {
            NSString *province = _startAddress.province;
            NSString *district = _startAddress.district;
            NSString *city_cn = _startAddress.city;
            NSString *city_code = self.adCode;
            element.start.province = province?province:@"";//省
            element.start.district = district?district:@"";//区
            element.start.city_cn = city_cn?city_cn:@"";//市
            element.start.city_code = city_code?city_code:@"";//城市行政编码
            NSLog(@"逆geo检索发送成功");
            NSLog(@"输出的省份:%@ --城市:%@ --区:%@ --城市编码:%@",province,district,city_cn,city_code);
        }  else  {
            NSLog(@"逆geo检索发送失败");
        }
        
        CGFloat endLat = element.end.location.lat;
        CGFloat endLng = element.end.location.lng;
        CLLocation *endLocation = [[CLLocation alloc] initWithLatitude:endLat longitude:endLng];
        CLGeocoder *geocoderTwo = [[CLGeocoder alloc] init];
        [geocoderTwo reverseGeocodeLocation:endLocation completionHandler:^(NSArray *array, NSError *error) {
            if (array.count > 0) {
                CLPlacemark *placemark = [array objectAtIndex:0];
                if (placemark != nil) {
                    NSString *provinceTwo = placemark.administrativeArea;
                    NSString *districtTwo = placemark.subLocality;
                    NSString *city_cnTwo = placemark.locality;
                    element.end.province = provinceTwo?provinceTwo:@"";
                    element.end.district = districtTwo?districtTwo:@"";
                    element.end.city_cn = city_cnTwo?city_cnTwo:@"";
                    NSLog(@"geocoderTwo--输出的省份:%@ --城市:%@ --区:%@",provinceTwo,districtTwo,city_cnTwo);
                }
            }
        }];
        //获取ID(用上面方法可解决首页点击历史记录地址的时候下面方法无法获取“省、市”的问题)
        self.searchTwo = [[BMKGeoCodeSearch alloc] init];
        self.searchTwo.delegate = self;
        BMKReverseGeoCodeSearchOption *reverseGeoCodeOptionTwo = [[BMKReverseGeoCodeSearchOption alloc]init];
        reverseGeoCodeOptionTwo.location = endLocation.coordinate;
        reverseGeoCodeOptionTwo.isLatestAdmin = YES;
        BOOL flagTwo = [self.searchTwo reverseGeoCode: reverseGeoCodeOptionTwo];
        if (flagTwo) {
            NSString *city_codeTwo = self.adCodeTwo;
            element.end.city_code = city_codeTwo?city_codeTwo:@"";
            NSLog(@"searchTwo输出城市的区id:%@",city_codeTwo);
        }
        return element;
    }
    
    // 逆编码结果
    - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error {
        
        if (error == BMK_SEARCH_NO_ERROR) {
            if (searcher == self.search) {
                self.adCode = result.addressDetail.adCode;
                NSLog(@"adCode返回结果:%@",self.adCode);
            } else if (searcher == self.searchTwo) {
                self.adCodeTwo = result.addressDetail.adCode;
                NSLog(@"adCodeTwo返回结果:%@",self.adCodeTwo);
            }
        } else {
            NSLog(@"检索失败");
        }
    }
    

    相关文章

      网友评论

          本文标题:开发问题笔记

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