Commit 53833bb178c11208b8f970188cbcc517a2e2faa6
1 parent
4600349c
no message
Showing
20 changed files
with
906 additions
and
13 deletions
CNLiveMapModule.podspec
| ... | ... | @@ -37,7 +37,7 @@ Pod::Spec.new do |s| |
| 37 | 37 | ############################################################################# |
| 38 | 38 | ##################################Controller##################################### |
| 39 | 39 | s.subspec 'Controller' do |ss| |
| 40 | - ss.source_files = 'CNLiveMapModule/Classes/Controller/*.{h,m}' | |
| 40 | + ss.source_files = 'CNLiveMapModule/Classes/Controller/*' | |
| 41 | 41 | ss.dependency 'CNLiveMapModule/View' |
| 42 | 42 | end |
| 43 | 43 | ############################################################################# | ... | ... |
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/backWhite.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "idiom" : "universal", | |
| 9 | + "filename" : "backWhite@2x.png", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "filename" : "backWhite@3x.png", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "version" : 1, | |
| 20 | + "author" : "xcode" | |
| 21 | + } | |
| 22 | +} | |
| 0 | 23 | \ No newline at end of file | ... | ... |
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/backWhite.imageset/backWhite@2x.png
0 → 100644
2.03 KB
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/backWhite.imageset/backWhite@3x.png
0 → 100644
2.28 KB
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/pyq_fengxiang.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "idiom" : "universal", | |
| 9 | + "filename" : "pyq_fengxiang@2x.png", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "filename" : "pyq_fengxiang@3x.png", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "version" : 1, | |
| 20 | + "author" : "xcode" | |
| 21 | + } | |
| 22 | +} | |
| 0 | 23 | \ No newline at end of file | ... | ... |
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/pyq_fengxiang.imageset/pyq_fengxiang@2x.png
0 → 100644
1.15 KB
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/pyq_fengxiang.imageset/pyq_fengxiang@3x.png
0 → 100644
1.3 KB
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/userPosition.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "filename" : "userPosition.png", | |
| 6 | + "scale" : "1x" | |
| 7 | + }, | |
| 8 | + { | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "version" : 1, | |
| 19 | + "author" : "xcode" | |
| 20 | + } | |
| 21 | +} | |
| 0 | 22 | \ No newline at end of file | ... | ... |
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/userPosition.imageset/userPosition.png
0 → 100644
3.58 KB
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/where_route.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "idiom" : "universal", | |
| 9 | + "filename" : "where_route@2x.png", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "filename" : "where_route@3x.png", | |
| 15 | + "scale" : "3x" | |
| 16 | + } | |
| 17 | + ], | |
| 18 | + "info" : { | |
| 19 | + "version" : 1, | |
| 20 | + "author" : "xcode" | |
| 21 | + } | |
| 22 | +} | |
| 0 | 23 | \ No newline at end of file | ... | ... |
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/where_route.imageset/where_route@2x.png
0 → 100644
5.32 KB
CNLiveMapModule/Assets/CNLiveMapModule.xcassets/where_route.imageset/where_route@3x.png
0 → 100644
8.89 KB
CNLiveMapModule/Classes/Controller/CNLiveMapDetailViewController.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveMapDetailViewController.h | |
| 3 | +// AFNetworking | |
| 4 | +// | |
| 5 | +// Created by open on 2019/11/26. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import "CNCommonViewController.h" | |
| 9 | + | |
| 10 | +NS_ASSUME_NONNULL_BEGIN | |
| 11 | + | |
| 12 | +@interface CNLiveMapDetailViewController : CNCommonViewController | |
| 13 | +@property (nonatomic, weak) id<CNLiveMapPositionDelegate> delegate; | |
| 14 | + | |
| 15 | +//@property (nonatomic, strong) IMAMsg *msg;//需要转发的消息 | |
| 16 | +//@property (nonatomic, strong) IMAConversation *conversation; | |
| 17 | +//locationCoordinate是发送出去的地点的经纬度坐标 | |
| 18 | +@property (nonatomic, assign) CLLocationCoordinate2D locationCoordinate; | |
| 19 | +@property (nonatomic, copy) NSString *img; | |
| 20 | +//此array是发送出去的地点名称(0)和地点地址(1) | |
| 21 | +@property (nonatomic, strong) NSArray *locationInfo; | |
| 22 | +@end | |
| 23 | + | |
| 24 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveMapModule/Classes/Controller/CNLiveMapDetailViewController.mm
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveMapDetailViewController.m | |
| 3 | +// AFNetworking | |
| 4 | +// | |
| 5 | +// Created by open on 2019/11/26. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import "CNLiveMapDetailViewController.h" | |
| 9 | + | |
| 10 | +@interface CNLiveMapDetailViewController () | |
| 11 | +< | |
| 12 | +BMKMapViewDelegate, | |
| 13 | +BMKLocationManagerDelegate, | |
| 14 | +BMKRouteSearchDelegate | |
| 15 | +> | |
| 16 | +@property (nonatomic, strong) UIView *bottomView; | |
| 17 | +@property (nonatomic, strong) UILabel *nameLab; | |
| 18 | +@property (nonatomic, strong) UILabel *addressLab; | |
| 19 | +@property (nonatomic, strong) UIButton *showListBtn; | |
| 20 | +@property (nonatomic, strong) BMKMapView *mapView;//地图 | |
| 21 | +@property (nonatomic, strong) UIButton *resetBtn; | |
| 22 | +@property (nonatomic, assign) CLLocationCoordinate2D mineLocationCoordinate; | |
| 23 | + | |
| 24 | +@property (nonatomic, strong) BMKLocationManager *locationManager;//定位管理 | |
| 25 | +@property (nonatomic, strong) BMKUserLocation *userLocation; //当前位置对象 | |
| 26 | +@property (nonatomic, strong) BMKPointAnnotation *annotation;//标注 | |
| 27 | +@property (nonatomic, assign) BOOL isLocation;//定位是否成功 | |
| 28 | +@property (nonatomic, strong) NSMutableArray *listSelectArray; | |
| 29 | +/* 起始点经纬度. */ | |
| 30 | +@property (nonatomic) CLLocationCoordinate2D startCoordinate; | |
| 31 | +/* 终点经纬度. */ | |
| 32 | +@property (nonatomic) CLLocationCoordinate2D destinationCoordinate; | |
| 33 | +@property (nonatomic, strong) NSMutableArray *maps; | |
| 34 | +@end | |
| 35 | + | |
| 36 | +@implementation CNLiveMapDetailViewController{ | |
| 37 | + BOOL _isShowRoute; | |
| 38 | +} | |
| 39 | + | |
| 40 | +-(void)viewWillAppear:(BOOL)animated{ | |
| 41 | + [super viewWillAppear:animated]; | |
| 42 | + [self.navigationController setNavigationBarHidden:YES animated:animated]; | |
| 43 | + [_mapView viewWillAppear]; | |
| 44 | + _locationManager.delegate = self; | |
| 45 | +} | |
| 46 | + | |
| 47 | +-(void)viewWillDisappear:(BOOL)animated{ | |
| 48 | + [super viewWillDisappear:animated]; | |
| 49 | + [self.navigationController setNavigationBarHidden:NO animated:animated]; | |
| 50 | + [_mapView viewWillDisappear]; | |
| 51 | + _locationManager.delegate = nil; | |
| 52 | +} | |
| 53 | + | |
| 54 | +- (void)viewDidLoad { | |
| 55 | + [super viewDidLoad]; | |
| 56 | + // Do any additional setup after loading the view. | |
| 57 | + [self.view addSubview:self.bottomView]; | |
| 58 | + [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 59 | + make.bottom.equalTo(self.view.mas_bottom).offset(-kVerticalBottomSafeHeight); | |
| 60 | + make.left.right.equalTo(self.view); | |
| 61 | + make.height.mas_equalTo(84); | |
| 62 | + }]; | |
| 63 | + [self.bottomView addSubview:self.showListBtn]; | |
| 64 | + [self.showListBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 65 | + make.centerY.equalTo(self.bottomView); | |
| 66 | + make.right.equalTo(self.bottomView.mas_right).offset(-15); | |
| 67 | + make.size.mas_equalTo(CGSizeMake(54, 54)); | |
| 68 | + }]; | |
| 69 | + [self.bottomView addSubview:self.nameLab]; | |
| 70 | + self.nameLab.text = self.locationInfo[0]; | |
| 71 | + [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 72 | + make.left.equalTo(self.bottomView).offset(15); | |
| 73 | + make.right.equalTo(self.showListBtn.mas_left).offset(-15); | |
| 74 | + make.top.equalTo(self.showListBtn.mas_top).offset(5); | |
| 75 | + }]; | |
| 76 | + [self.bottomView addSubview:self.addressLab]; | |
| 77 | + self.addressLab.text = self.locationInfo[1]; | |
| 78 | + [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 79 | + make.left.equalTo(self.bottomView).offset(15); | |
| 80 | + make.right.equalTo(self.showListBtn.mas_left).offset(-15); | |
| 81 | + make.bottom.equalTo(self.showListBtn.mas_bottom).offset(-5); | |
| 82 | + }]; | |
| 83 | + [self.view addSubview:self.mapView]; | |
| 84 | + [self.mapView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 85 | + make.top.left.right.equalTo(self.view); | |
| 86 | + make.bottom.equalTo(self.bottomView.mas_top); | |
| 87 | + }]; | |
| 88 | + CGPoint p = self.mapView.compassPosition; | |
| 89 | + p.x += 60; | |
| 90 | + self.mapView.compassPosition = p; | |
| 91 | + CGPoint p1 = self.mapView.mapScaleBarPosition; | |
| 92 | + p1.y = SCREEN_WIDTH - 84 - kVerticalBottomSafeHeight - 30; | |
| 93 | + self.mapView.mapScaleBarPosition = p1; | |
| 94 | + [self.mapView addSubview:self.resetBtn]; | |
| 95 | + [self.resetBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 96 | + make.right.equalTo(self.mapView.mas_right).offset(-15); | |
| 97 | + make.bottom.equalTo(self.mapView.mas_bottom).offset(-24); | |
| 98 | + make.size.mas_equalTo(CGSizeMake(50, 50)); | |
| 99 | + }]; | |
| 100 | + [self addTopView]; | |
| 101 | +} | |
| 102 | + | |
| 103 | +#pragma mark -- private | |
| 104 | +- (void)addTopView{ | |
| 105 | + //返回按钮 | |
| 106 | + UIButton *backBtn = [[UIButton alloc] init]; | |
| 107 | + backBtn.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.8]; | |
| 108 | + [backBtn setImage:[UIImage imageNamed:@"backWhite"] forState:UIControlStateNormal]; | |
| 109 | + [backBtn addTarget:self action:@selector(backController) forControlEvents:UIControlEventTouchUpInside]; | |
| 110 | + [self.mapView addSubview:backBtn]; | |
| 111 | + [backBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 112 | + make.left.equalTo(self.mapView).offset(15); | |
| 113 | + make.top.equalTo(self.mapView).offset(30+kVerticalTopHeight); | |
| 114 | + make.size.mas_equalTo(CGSizeMake(42, 42)); | |
| 115 | + }]; | |
| 116 | + backBtn.layer.cornerRadius = 8; | |
| 117 | + backBtn.layer.masksToBounds = YES; | |
| 118 | + | |
| 119 | + UIButton *sendBtn = [[UIButton alloc] init]; | |
| 120 | + sendBtn.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.8]; | |
| 121 | + [sendBtn addTarget:self action:@selector(selectToOperation) forControlEvents:UIControlEventTouchUpInside]; | |
| 122 | + [sendBtn setImage:[UIImage imageNamed:@"pyq_fengxiang"] forState:UIControlStateNormal]; | |
| 123 | + [self.mapView addSubview:sendBtn]; | |
| 124 | + [sendBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 125 | + make.right.equalTo(self.mapView.mas_right).offset(-15); | |
| 126 | + make.top.equalTo(self.mapView).offset(30+kVerticalTopHeight); | |
| 127 | + make.size.mas_equalTo(CGSizeMake(42, 42)); | |
| 128 | + }]; | |
| 129 | + sendBtn.layer.cornerRadius = 8; | |
| 130 | + sendBtn.layer.masksToBounds = YES; | |
| 131 | +} | |
| 132 | + | |
| 133 | +- (void)backController{ | |
| 134 | + [self.navigationController popViewControllerAnimated:YES]; | |
| 135 | +} | |
| 136 | + | |
| 137 | +- (void)selectToOperation{ | |
| 138 | + MJWeakSelf | |
| 139 | + [self.view createAlertViewTitleArray:@[@"发送给朋友"] subTitleArr:@[@""] textColor:UIColorMake(11, 190, 6) subTitleColor:UIColorMake(152, 152, 152) firstFont:UIFontMake(18) font:UIFontMake(18) subFont:UIFontMake(18) cancelTitle:@"取消" cancelFont:UIFontMake(18) cancelTitleColor:UIColorMake(102, 102, 102) actionBlock:^(UIButton *button, NSInteger didRow) { | |
| 140 | + switch (didRow) { | |
| 141 | + case 0: | |
| 142 | + { | |
| 143 | + if (self.delegate && [self.delegate respondsToSelector:@selector(forwardingLocation:image:addressName:)]) { | |
| 144 | + [self.delegate forwardingLocation:self.locationCoordinate image:self.img addressName:self.locationInfo]; | |
| 145 | + [weakSelf.navigationController popViewControllerAnimated:YES]; | |
| 146 | + }else{ | |
| 147 | + [QMUITips showError:@"发送失败" inView:[UIApplication sharedApplication].delegate.window hideAfterDelay:1.5]; | |
| 148 | + } | |
| 149 | +// CNMessageForwardingController *vc= [[CNMessageForwardingController alloc] init]; | |
| 150 | +// vc.msgsArray = @[weakSelf.msg]; | |
| 151 | +// vc.conversation = weakSelf.conversation; | |
| 152 | +// [weakSelf.navigationController pushViewController:vc animated:YES]; | |
| 153 | + } | |
| 154 | + break; | |
| 155 | + default: | |
| 156 | + break; | |
| 157 | + } | |
| 158 | + }]; | |
| 159 | +} | |
| 160 | + | |
| 161 | +- (void)resetPosition{ | |
| 162 | + if (self.isLocation) { | |
| 163 | + [self.mapView setCenterCoordinate:self.userLocation.location.coordinate animated:YES]; | |
| 164 | + }else{//没自动定位到位置,需要手动定位 | |
| 165 | + @try { | |
| 166 | + [self.locationManager stopUpdatingLocation]; | |
| 167 | + } @catch (NSException *exception) { | |
| 168 | + NSLog(@"CNBDMapDetailViewController.mm 崩溃了"); | |
| 169 | + } | |
| 170 | + [QMUITips showLoadingInView:self.view]; | |
| 171 | + MJWeakSelf | |
| 172 | + [self.locationManager requestLocationWithReGeocode:NO withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) { | |
| 173 | + [QMUITips hideAllTips]; | |
| 174 | + BOOL isError = false; | |
| 175 | + if (error) | |
| 176 | + { | |
| 177 | + isError = YES; | |
| 178 | +// NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription); | |
| 179 | + } | |
| 180 | + if (location) {//得到定位信息,添加annotation | |
| 181 | + if (location.location) { | |
| 182 | + NSLog(@"LOC = %@",location.location); | |
| 183 | + //把地图放到位置中心点 | |
| 184 | + weakSelf.mineLocationCoordinate = location.location.coordinate; | |
| 185 | + [weakSelf.mapView setCenterCoordinate:weakSelf.mineLocationCoordinate animated:YES]; | |
| 186 | + //实现该方法,否则定位图标不出现 | |
| 187 | + weakSelf.userLocation.location = location.location; | |
| 188 | + [weakSelf.mapView updateLocationData:weakSelf.userLocation]; | |
| 189 | + | |
| 190 | + } | |
| 191 | + }else{ | |
| 192 | + isError = YES; | |
| 193 | + } | |
| 194 | + if ([error.localizedDescription containsString:@"网络"] && [error.localizedDescription containsString:@"失败"]) { | |
| 195 | + UIAlertController *con = [UIAlertController alertControllerWithTitle:@"" message:@"网络错误,请检查您的网络。" preferredStyle:UIAlertControllerStyleAlert]; | |
| 196 | + UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | |
| 197 | + }]; | |
| 198 | + [con addAction:action1]; | |
| 199 | + [weakSelf presentViewController:con animated:YES completion:nil]; | |
| 200 | + }else{ | |
| 201 | + if (isError) { | |
| 202 | + UIAlertController *con = [UIAlertController alertControllerWithTitle:@"" message:@"无法获取您的位置信息。" preferredStyle:UIAlertControllerStyleAlert]; | |
| 203 | + UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | |
| 204 | + }]; | |
| 205 | + [con addAction:action1]; | |
| 206 | + [weakSelf presentViewController:con animated:YES completion:nil]; | |
| 207 | + } | |
| 208 | + } | |
| 209 | + [self.locationManager startUpdatingLocation]; | |
| 210 | + [self.locationManager startUpdatingHeading]; | |
| 211 | + }]; | |
| 212 | + | |
| 213 | + } | |
| 214 | +} | |
| 215 | + | |
| 216 | +- (void)showListSelectBtn{ | |
| 217 | + [self initListSelectArray]; | |
| 218 | + MJWeakSelf | |
| 219 | + [self.view createAlertViewTitleArray:self.listSelectArray textColor:UIColorMake(40, 40, 40) font:UIFontMake(15) actionBlock:^(UIButton *button, NSInteger didRow) { | |
| 220 | + if (didRow == 0) { | |
| 221 | + if ([weakSelf.listSelectArray[0] isEqualToString:@"隐藏路线"]) { | |
| 222 | + [weakSelf hideWalkLine]; | |
| 223 | + [weakSelf.listSelectArray replaceObjectAtIndex:0 withObject:@"显示路线"]; | |
| 224 | + self->_isShowRoute = NO; | |
| 225 | + return; | |
| 226 | + }else{ | |
| 227 | + self->_isShowRoute = YES; | |
| 228 | + [weakSelf.listSelectArray replaceObjectAtIndex:0 withObject:@"隐藏路线"]; | |
| 229 | + [self walkLine]; | |
| 230 | + } | |
| 231 | + //显示路线 | |
| 232 | + if (weakSelf.mineLocationCoordinate.latitude == 0) { | |
| 233 | + QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | |
| 234 | + // [weakSelf.navigationController popViewControllerAnimated:YES]; | |
| 235 | + }]; | |
| 236 | + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"无法获取你的位置信息。\n 请到手机系统的[隐私]->[定位服务]中打开定位服务,并允许网家家使用定位服务" preferredStyle:QMUIAlertControllerStyleAlert]; | |
| 237 | + [alertController addAction:action1]; | |
| 238 | + [alertController showWithAnimated:YES]; | |
| 239 | + return; | |
| 240 | + } | |
| 241 | + return; | |
| 242 | + } | |
| 243 | + CLLocationCoordinate2D startLocation = self.mineLocationCoordinate; | |
| 244 | + CLLocationCoordinate2D endLocation = self.locationCoordinate; | |
| 245 | + | |
| 246 | + if (didRow == self.maps.count) {//苹果地图 | |
| 247 | + MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc]initWithCoordinate:startLocation addressDictionary:nil]]; | |
| 248 | + currentLocation.name = @"我的位置"; | |
| 249 | + MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:endLocation addressDictionary:nil]]; | |
| 250 | + toLocation.name = self.locationInfo[0]; | |
| 251 | + [MKMapItem openMapsWithItems:@[currentLocation, toLocation] | |
| 252 | + launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, | |
| 253 | + MKLaunchOptionsMapTypeKey:[NSNumber numberWithInteger:MKMapTypeStandard], | |
| 254 | + MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]}]; | |
| 255 | + | |
| 256 | + return; | |
| 257 | + } | |
| 258 | + NSString *urlString = self.maps[didRow-1][@"url"]; | |
| 259 | + if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) { | |
| 260 | + if (@available(iOS 10.0, *)) { | |
| 261 | + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) { | |
| 262 | + }]; | |
| 263 | + } else { | |
| 264 | + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; | |
| 265 | + } | |
| 266 | + }else{ | |
| 267 | + [QMUITips showError:@"打开失败" inView:self.view hideAfterDelay:1.5]; | |
| 268 | + } | |
| 269 | + | |
| 270 | + }]; | |
| 271 | +} | |
| 272 | +- (void)initListSelectArray{ | |
| 273 | + self.listSelectArray = [NSMutableArray arrayWithCapacity:0]; | |
| 274 | + [self.listSelectArray removeAllObjects]; | |
| 275 | + [self.listSelectArray addObject:_isShowRoute?@"隐藏路线":@"显示路线"]; | |
| 276 | + self.maps = [NSMutableArray arrayWithCapacity:0]; | |
| 277 | + [self.maps removeAllObjects]; | |
| 278 | + CLLocationCoordinate2D startLocation = self.mineLocationCoordinate; | |
| 279 | + CLLocationCoordinate2D endLocation = self.locationCoordinate; | |
| 280 | + //高德地图 | |
| 281 | + if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) { | |
| 282 | + NSMutableDictionary *gaodeMapDic = [NSMutableDictionary dictionary]; | |
| 283 | + gaodeMapDic[@"title"] = @"高德地图"; | |
| 284 | + [self.listSelectArray addObject:@"高德地图"]; | |
| 285 | + NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=%f&slon=%f&sname=我的位置&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&t=0",startLocation.latitude,startLocation.longitude,endLocation.latitude,endLocation.longitude,self.locationInfo[0]] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; | |
| 286 | + gaodeMapDic[@"url"] = urlString; | |
| 287 | + [self.maps addObject:gaodeMapDic]; | |
| 288 | + } | |
| 289 | + | |
| 290 | + | |
| 291 | + //百度地图 | |
| 292 | + if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) { | |
| 293 | + NSMutableDictionary *baiduMapDic = [NSMutableDictionary dictionary]; | |
| 294 | + baiduMapDic[@"title"] = @"百度地图"; | |
| 295 | + [self.listSelectArray addObject:@"百度地图"]; | |
| 296 | + NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=%f,%f|name:%@&destination=%f,%f|name:%@&mode=driving",startLocation.latitude,startLocation.longitude,@"我的位置",endLocation.latitude,endLocation.longitude,self.locationInfo[0]] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; | |
| 297 | + baiduMapDic[@"url"] = urlString; | |
| 298 | + [self.maps addObject:baiduMapDic]; | |
| 299 | + } | |
| 300 | + | |
| 301 | + //腾讯地图 | |
| 302 | + if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) { | |
| 303 | + NSMutableDictionary *qqMapDic = [NSMutableDictionary dictionary]; | |
| 304 | + qqMapDic[@"title"] = @"腾讯地图"; | |
| 305 | + [self.listSelectArray addObject:@"腾讯地图"]; | |
| 306 | + NSString *urlStr = [NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=我的位置&fromcoord=%f, %f&to=%@&tocoord=%f,%f",startLocation.latitude,startLocation.longitude,self.locationInfo[0],endLocation.latitude,endLocation.longitude]; | |
| 307 | + qqMapDic[@"url"] = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; | |
| 308 | + [self.maps addObject:qqMapDic]; | |
| 309 | + } | |
| 310 | + | |
| 311 | + //苹果原生地图-苹果原生地图方法和其他不一样,如果没有,提示,确定后去App Store下载 | |
| 312 | + NSMutableDictionary *iosMapDic = [NSMutableDictionary dictionary]; | |
| 313 | + iosMapDic[@"title"] = @"苹果地图"; | |
| 314 | + iosMapDic[@"lat"] = [NSNumber numberWithDouble:endLocation.latitude]; | |
| 315 | + iosMapDic[@"lng"] = [NSNumber numberWithDouble:endLocation.longitude]; | |
| 316 | + [self.maps addObject:iosMapDic]; | |
| 317 | + [self.listSelectArray addObject:@"苹果地图"]; | |
| 318 | + | |
| 319 | +} | |
| 320 | +- (void)walkLine{ | |
| 321 | + BMKRouteSearch *routeSearch = [[BMKRouteSearch alloc] init]; | |
| 322 | + routeSearch.delegate = self; | |
| 323 | + BMKPlanNode* start = [[BMKPlanNode alloc] init]; | |
| 324 | + start.pt = self.mineLocationCoordinate; | |
| 325 | + // start.name = @"天安门"; | |
| 326 | + // start.cityName = @"北京"; | |
| 327 | + BMKPlanNode* end = [[BMKPlanNode alloc] init]; | |
| 328 | + end.pt = self.locationCoordinate; | |
| 329 | + // end.name = @"天津站"; | |
| 330 | + // end.cityName = @"天津"; | |
| 331 | + BMKWalkingRoutePlanOption *walkingRouteSearchOption = [[BMKWalkingRoutePlanOption alloc] init]; | |
| 332 | + walkingRouteSearchOption.from = start; | |
| 333 | + walkingRouteSearchOption.to = end; | |
| 334 | + BOOL flag = [routeSearch walkingSearch:walkingRouteSearchOption]; | |
| 335 | + if (flag) { | |
| 336 | + NSLog(@"步行规划检索发送成功"); | |
| 337 | + } else{ | |
| 338 | + NSLog(@"步行规划检索发送失败"); | |
| 339 | + } | |
| 340 | +} | |
| 341 | + | |
| 342 | +- (void)hideWalkLine{ | |
| 343 | + [self.mapView removeOverlays:self.mapView.overlays]; | |
| 344 | +} | |
| 345 | + | |
| 346 | +#pragma mark -- 路线delegate | |
| 347 | +/** | |
| 348 | + 根据overlay生成对应的BMKOverlayView | |
| 349 | + | |
| 350 | + @param mapView 地图View | |
| 351 | + @param overlay 指定的overlay | |
| 352 | + @return 生成的覆盖物View | |
| 353 | + */ | |
| 354 | +- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay { | |
| 355 | + if ([overlay isKindOfClass:[BMKPolyline class]]) { | |
| 356 | + //初始化一个overlay并返回相应的BMKPolylineView的实例 | |
| 357 | + BMKPolylineView *polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay]; | |
| 358 | + //设置polylineView的填充色 | |
| 359 | + polylineView.fillColor = [RGBOF(0x5BC4A4) colorWithAlphaComponent:1]; | |
| 360 | + //设置polylineView的画笔(边框)颜色 | |
| 361 | + polylineView.strokeColor = [RGBOF(0x5BC4A4) colorWithAlphaComponent:0.7]; | |
| 362 | + //设置polygonView的线宽度 | |
| 363 | + polylineView.lineWidth = 2.0; | |
| 364 | + return polylineView; | |
| 365 | + } | |
| 366 | + return nil; | |
| 367 | +} | |
| 368 | + | |
| 369 | +- (void)onGetWalkingRouteResult:(BMKRouteSearch *)searcher result:(BMKWalkingRouteResult *)result errorCode:(BMKSearchErrorCode)error { | |
| 370 | + [self.mapView removeOverlays:self.mapView.overlays]; | |
| 371 | + if (error == BMK_SEARCH_NO_ERROR) { | |
| 372 | + //+polylineWithPoints: count:坐标点的个数 | |
| 373 | + __block NSUInteger pointCount = 0; | |
| 374 | + //获取所有步行路线中第一条路线 | |
| 375 | + BMKWalkingRouteLine *routeline = (BMKWalkingRouteLine *)result.routes[0]; | |
| 376 | + //遍历步行路线中的所有路段 | |
| 377 | +// BMKWalkingStep *startStep = [[BMKWalkingStep alloc] init]; | |
| 378 | +// startStep. | |
| 379 | + | |
| 380 | + [routeline.steps enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | |
| 381 | + //获取步行路线中的每条路段 | |
| 382 | + BMKWalkingStep *step = routeline.steps[idx]; | |
| 383 | +// //初始化标注类BMKPointAnnotation的实例 | |
| 384 | +// BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init]; | |
| 385 | +// //设置标注的经纬度坐标为子路段的入口经纬度 | |
| 386 | +// annotation.coordinate = step.entrace.location; | |
| 387 | +// //设置标注的标题为子路段的说明 | |
| 388 | +// annotation.title = step.entraceInstruction; | |
| 389 | +// /** | |
| 390 | +// | |
| 391 | +// 当前地图添加标注,需要实现BMKMapViewDelegate的-mapView:viewForAnnotation:方法 | |
| 392 | +// 来生成标注对应的View | |
| 393 | +// @param annotation 要添加的标注 | |
| 394 | +// */ | |
| 395 | +// [_mapView addAnnotation:annotation]; | |
| 396 | + //统计路段所经过的地理坐标集合内点的个数 | |
| 397 | + pointCount += step.pointsCount; | |
| 398 | + }]; | |
| 399 | + //+polylineWithPoints: count:指定的直角坐标点数组 | |
| 400 | + BMKMapPoint *points = new BMKMapPoint[pointCount]; | |
| 401 | + __block NSUInteger j = 0; | |
| 402 | + //遍历步行路线中的所有路段 | |
| 403 | + [routeline.steps enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | |
| 404 | + //获取步行路线中的每条路段 | |
| 405 | + BMKWalkingStep *step = routeline.steps[idx]; | |
| 406 | + //遍历路段所经过的地理坐标集合 | |
| 407 | + for (NSUInteger i = 0; i < step.pointsCount; i ++) { | |
| 408 | + //将每条路段所经过的地理坐标点赋值给points | |
| 409 | + points[j].x = step.points[i].x; | |
| 410 | + points[j].y = step.points[i].y; | |
| 411 | + j ++; | |
| 412 | + } | |
| 413 | + }]; | |
| 414 | + | |
| 415 | + //根据指定直角坐标点生成一段折线 | |
| 416 | + BMKPolyline *polyline = [BMKPolyline polylineWithPoints:points count:pointCount]; | |
| 417 | + /** | |
| 418 | + 向地图View添加Overlay,需要实现BMKMapViewDelegate的-mapView:viewForOverlay:方法 | |
| 419 | + 来生成标注对应的View | |
| 420 | + 15076875152 | |
| 421 | + 17600128270 | |
| 422 | + @param overlay 要添加的overlay | |
| 423 | + */ | |
| 424 | + [_mapView addOverlay:polyline]; | |
| 425 | + //根据polyline设置地图范围 | |
| 426 | + [self mapViewFitPolyline:polyline withMapView:self.mapView]; | |
| 427 | + }else{ | |
| 428 | + _isShowRoute = NO; | |
| 429 | + if (error == BMK_SEARCH_NETWOKR_ERROR) { | |
| 430 | + [QMUITips showInfo:@"网络错误,请检查网络。" inView:self.view hideAfterDelay:1.5]; | |
| 431 | + }else{ | |
| 432 | + [QMUITips showInfo:@"规划路线失败,请重试。" inView:self.view hideAfterDelay:1.5]; | |
| 433 | + } | |
| 434 | + } | |
| 435 | +} | |
| 436 | + | |
| 437 | +//根据polyline设置地图范围 | |
| 438 | +- (void)mapViewFitPolyline:(BMKPolyline *)polyline withMapView:(BMKMapView *)mapView { | |
| 439 | + double leftTop_x, leftTop_y, rightBottom_x, rightBottom_y; | |
| 440 | + if (polyline.pointCount < 1) { | |
| 441 | + return; | |
| 442 | + } | |
| 443 | + BMKMapPoint pt = polyline.points[0]; | |
| 444 | + leftTop_x = pt.x; | |
| 445 | + leftTop_y = pt.y; | |
| 446 | + //左上方的点lefttop坐标(leftTop_x,leftTop_y) | |
| 447 | + rightBottom_x = pt.x; | |
| 448 | + rightBottom_y = pt.y; | |
| 449 | + //右底部的点rightbottom坐标(rightBottom_x,rightBottom_y) | |
| 450 | + for (int i = 1; i < polyline.pointCount; i++) { | |
| 451 | + BMKMapPoint point = polyline.points[i]; | |
| 452 | + if (point.x < leftTop_x) { | |
| 453 | + leftTop_x = point.x; | |
| 454 | + } | |
| 455 | + if (point.x > rightBottom_x) { | |
| 456 | + rightBottom_x = point.x; | |
| 457 | + } | |
| 458 | + if (point.y < leftTop_y) { | |
| 459 | + leftTop_y = point.y; | |
| 460 | + } | |
| 461 | + if (point.y > rightBottom_y) { | |
| 462 | + rightBottom_y = point.y; | |
| 463 | + } | |
| 464 | + } | |
| 465 | + BMKMapRect rect; | |
| 466 | + rect.origin = BMKMapPointMake(leftTop_x , leftTop_y); | |
| 467 | + rect.size = BMKMapSizeMake(rightBottom_x - leftTop_x, rightBottom_y - leftTop_y); | |
| 468 | + UIEdgeInsets padding = UIEdgeInsetsMake(20, 10, 20, 10); | |
| 469 | + [mapView fitVisibleMapRect:rect edgePadding:padding withAnimated:YES]; | |
| 470 | +} | |
| 471 | +#pragma mark -- 地图delegate | |
| 472 | +-(void)mapViewDidFinishLoading:(BMKMapView *)mapView{ | |
| 473 | + //添加地图上的标注,并把中心点定位到标注处 | |
| 474 | + self.annotation.coordinate = self.locationCoordinate; | |
| 475 | + [mapView setCenterCoordinate:self.locationCoordinate animated:YES]; | |
| 476 | + [mapView addAnnotation:self.annotation]; | |
| 477 | + [self.locationManager startUpdatingLocation]; | |
| 478 | + [self.locationManager startUpdatingHeading]; | |
| 479 | +} | |
| 480 | + | |
| 481 | +- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation | |
| 482 | +{ | |
| 483 | + if ([annotation isKindOfClass:[BMKPointAnnotation class]]) { | |
| 484 | + static NSString *pointReuseIndentifier = @"pointReuseIndentifier"; | |
| 485 | + BMKPinAnnotationView*annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier]; | |
| 486 | + if (annotationView == nil) { | |
| 487 | + annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier]; | |
| 488 | + } | |
| 489 | + annotationView.image = [UIImage imageNamed:@"where_point_b"]; | |
| 490 | + annotationView.pinColor = BMKPinAnnotationColorRed; | |
| 491 | + // annotationView.canShowCallout= YES; //设置气泡可以弹出,默认为NO | |
| 492 | + // annotationView.animatesDrop=YES; //设置标注动画显示,默认为NO | |
| 493 | + // annotationView.draggable = YES; //设置标注可以拖动,默认为NO | |
| 494 | + return annotationView; | |
| 495 | + } | |
| 496 | + return nil; | |
| 497 | +} | |
| 498 | +#pragma mark -- 定位delegate | |
| 499 | +//权限改变 | |
| 500 | +- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ | |
| 501 | + if (status == kCLAuthorizationStatusDenied) { | |
| 502 | + MJWeakSelf | |
| 503 | + QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | |
| 504 | + [weakSelf.navigationController popViewControllerAnimated:YES]; | |
| 505 | + }]; | |
| 506 | + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"无法获取你的位置信息。\n 请到手机系统的[隐私]->[定位服务]中打开定位服务,并允许网家家使用定位服务" preferredStyle:QMUIAlertControllerStyleAlert]; | |
| 507 | + [alertController addAction:action1]; | |
| 508 | + [alertController showWithAnimated:YES]; | |
| 509 | + } | |
| 510 | +} | |
| 511 | + | |
| 512 | +- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager doRequestAlwaysAuthorization:(CLLocationManager * _Nonnull)locationManager{ | |
| 513 | + [locationManager requestAlwaysAuthorization]; | |
| 514 | +} | |
| 515 | +- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager didFailWithError:(NSError * _Nullable)error { | |
| 516 | + NSLog(@"定位失败"); | |
| 517 | + self.isLocation = NO; | |
| 518 | +} | |
| 519 | + | |
| 520 | +// 定位SDK中,方向变更的回调 | |
| 521 | +- (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateHeading:(CLHeading * _Nullable)heading{ | |
| 522 | + if (!heading) { | |
| 523 | + return; | |
| 524 | + } | |
| 525 | + self.userLocation.heading = heading; | |
| 526 | + [self.mapView updateLocationData:self.userLocation]; | |
| 527 | +} | |
| 528 | + | |
| 529 | + | |
| 530 | +// 定位SDK中,位置变更的回调 | |
| 531 | +- (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateLocation:(BMKLocation *)location orError:(NSError *)error { | |
| 532 | + if (error) { | |
| 533 | + self.isLocation = NO; | |
| 534 | + NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription); | |
| 535 | +// [QMUITips showInfo:@"位置更新失败" inView:self.view hideAfterDelay:0.5]; | |
| 536 | + }else{ | |
| 537 | + self.mineLocationCoordinate = location.location.coordinate; | |
| 538 | + self.isLocation = YES; | |
| 539 | + } | |
| 540 | + if (!location) { | |
| 541 | + return; | |
| 542 | + } | |
| 543 | +// [QMUITips showInfo:@"位置更新" inView:self.view hideAfterDelay:0.5]; | |
| 544 | + self.userLocation.location = location.location; | |
| 545 | + [self.mapView updateLocationData:self.userLocation];//动态更新我的位置数据 | |
| 546 | +} | |
| 547 | + | |
| 548 | +#pragma mark -- lazy | |
| 549 | +-(UIView *)bottomView{ | |
| 550 | + if (!_bottomView) { | |
| 551 | + _bottomView = [[UIView alloc] init]; | |
| 552 | + _bottomView.backgroundColor = [UIColor whiteColor]; | |
| 553 | + } | |
| 554 | + return _bottomView; | |
| 555 | +} | |
| 556 | + | |
| 557 | +-(UILabel *)nameLab{ | |
| 558 | + if (!_nameLab) { | |
| 559 | + _nameLab = [[UILabel alloc] init]; | |
| 560 | + _nameLab.font = [UIFont systemFontOfSize:21]; | |
| 561 | + _nameLab.textColor = [UIColor blackColor]; | |
| 562 | + } | |
| 563 | + return _nameLab; | |
| 564 | +} | |
| 565 | + | |
| 566 | +-(UILabel *)addressLab{ | |
| 567 | + if (!_addressLab) { | |
| 568 | + _addressLab = [[UILabel alloc] init]; | |
| 569 | + _addressLab.font = [UIFont systemFontOfSize:12]; | |
| 570 | + _addressLab.textColor = [UIColor blackColor]; | |
| 571 | + } | |
| 572 | + return _addressLab; | |
| 573 | +} | |
| 574 | + | |
| 575 | +-(UIButton *)showListBtn{ | |
| 576 | + if (!_showListBtn) { | |
| 577 | + _showListBtn = [[UIButton alloc] init]; | |
| 578 | + [_showListBtn setImage:[UIImage imageNamed:@"where_route"] forState:UIControlStateNormal]; | |
| 579 | + [_showListBtn addTarget:self action:@selector(showListSelectBtn) forControlEvents:UIControlEventTouchUpInside]; | |
| 580 | + } | |
| 581 | + return _showListBtn; | |
| 582 | +} | |
| 583 | + | |
| 584 | +- (BMKMapView *)mapView{ | |
| 585 | + if (!_mapView) { | |
| 586 | + _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, (self.view.height-44-20)/2)]; | |
| 587 | + _mapView.delegate = self; | |
| 588 | + _mapView.zoomLevel = 19;//缩放等级4-21 | |
| 589 | + _mapView.showMapScaleBar = YES;//显示比例尺 | |
| 590 | +// //打开实时路况图层 | |
| 591 | +// // [_mapView setTrafficEnabled:YES]; | |
| 592 | + _mapView.showsUserLocation = YES;//显示定位图层 | |
| 593 | +// //显示我的位置,我的位置图标和地图都不会旋转 | |
| 594 | + _mapView.userTrackingMode = BMKUserTrackingModeHeading; | |
| 595 | +// //更换我的位置图标 | |
| 596 | +// // self.mapView是BMKMapView对象 | |
| 597 | + BMKLocationViewDisplayParam *param = [[BMKLocationViewDisplayParam alloc] init]; | |
| 598 | +// //定位图标名称,需要将该图片放到 mapapi.bundle/images 目录下 | |
| 599 | +// // param.locationViewImgName = @"icon_nav_bus"; | |
| 600 | +// //用户自定义定位图标,V4.2.1以后支持 | |
| 601 | + param.locationViewImage = [UIImage imageNamed:@"userPosition"]; | |
| 602 | +// //根据配置参数更新定位图层样式 | |
| 603 | +// //设置显示精度圈,默认YES | |
| 604 | +// param.isAccuracyCircleShow = NO; | |
| 605 | + [_mapView updateLocationViewWithParam:param]; | |
| 606 | + | |
| 607 | + } | |
| 608 | + return _mapView; | |
| 609 | +} | |
| 610 | + | |
| 611 | +-(UIButton *)resetBtn{ | |
| 612 | + if (!_resetBtn) { | |
| 613 | + _resetBtn = [[UIButton alloc] init]; | |
| 614 | + [_resetBtn setImage:[UIImage imageNamed:@"where_select"] forState:UIControlStateNormal]; | |
| 615 | + [_resetBtn addTarget:self action:@selector(clickRestBtn) forControlEvents:UIControlEventTouchUpInside]; | |
| 616 | + } | |
| 617 | + return _resetBtn; | |
| 618 | +} | |
| 619 | + | |
| 620 | +- (void)clickRestBtn{ | |
| 621 | + [self resetPosition]; | |
| 622 | +} | |
| 623 | +-(BMKLocationManager *)locationManager{ | |
| 624 | + if (!_locationManager) { | |
| 625 | + //初始化实例 | |
| 626 | + _locationManager = [[BMKLocationManager alloc] init]; | |
| 627 | + //设置delegate | |
| 628 | + _locationManager.delegate = self; | |
| 629 | + //设置返回位置的坐标系类型 | |
| 630 | + _locationManager.coordinateType = BMKLocationCoordinateTypeGCJ02; | |
| 631 | + //设置距离过滤参数 | |
| 632 | + _locationManager.distanceFilter = 1.0f; | |
| 633 | + //设置预期精度参数 | |
| 634 | + _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; | |
| 635 | + //设置应用位置类型 | |
| 636 | + _locationManager.activityType = CLActivityTypeFitness; | |
| 637 | + //设置是否自动停止位置更新 | |
| 638 | + _locationManager.pausesLocationUpdatesAutomatically = NO; | |
| 639 | + //设置是否允许后台定位 | |
| 640 | + //_locationManager.allowsBackgroundLocationUpdates = YES; | |
| 641 | + //设置位置获取超时时间 | |
| 642 | +// _locationManager.locationTimeout = 10; | |
| 643 | + //设置获取地址信息超时时间 | |
| 644 | +// _locationManager.reGeocodeTimeout = 3; | |
| 645 | + } | |
| 646 | + return _locationManager; | |
| 647 | +} | |
| 648 | + | |
| 649 | +-(BMKUserLocation *)userLocation{ | |
| 650 | + if (!_userLocation) { | |
| 651 | + _userLocation = [[BMKUserLocation alloc] init]; | |
| 652 | + } | |
| 653 | + return _userLocation; | |
| 654 | +} | |
| 655 | + | |
| 656 | +-(BMKPointAnnotation *)annotation{ | |
| 657 | + if (!_annotation) { | |
| 658 | + _annotation = [[BMKPointAnnotation alloc] init]; | |
| 659 | + } | |
| 660 | + return _annotation; | |
| 661 | +} | |
| 662 | + | |
| 663 | +#pragma mark -- bundle图片 | |
| 664 | +/** | |
| 665 | + * 创建图片 | |
| 666 | + * | |
| 667 | + * @param imageName 图片名字 | |
| 668 | + * @param bundleName 图片所在的bundle名字 | |
| 669 | + * @param targetClass 类和bundle的同级目录 | |
| 670 | + * @return 返回UIImage | |
| 671 | + */ | |
| 672 | +- (UIImage *)getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 673 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 674 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 675 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 676 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 677 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 678 | +} | |
| 679 | +@end | ... | ... |
CNLiveMapModule/Classes/Controller/CNLiveMapViewController.h
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | NS_ASSUME_NONNULL_BEGIN |
| 12 | 12 | |
| 13 | 13 | @interface CNLiveMapViewController : CNCommonViewController |
| 14 | -@property (nonatomic, weak) id<CNLiveSendPositonDelegate> delegate; | |
| 14 | +@property (nonatomic, weak) id<CNLiveMapPositionDelegate> delegate; | |
| 15 | 15 | |
| 16 | 16 | @end |
| 17 | 17 | ... | ... |
CNLiveMapModule/Classes/Map_PrefixHeader.pch
| ... | ... | @@ -24,6 +24,7 @@ |
| 24 | 24 | #import <CNLiveEnvironment/CNLiveEnvironment.h> |
| 25 | 25 | #import <CNLiveCustomUI/CNLiveRefreshHeader.h> |
| 26 | 26 | #import <CNLiveServices/CNLiveServices.h> |
| 27 | +#import <UIMapKit/UIMapKit.h> | |
| 27 | 28 | // Include any system framework and library headers here that should be included in all compilation units. |
| 28 | 29 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. |
| 29 | 30 | ... | ... |
CNLiveMapModule/Classes/Module/CNLiveSendPositonService.m
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | #import "CNLiveSendPositonService.h" |
| 9 | 9 | #import "CNLiveServices.h" |
| 10 | 10 | #import "CNLiveMapViewController.h" |
| 11 | +#import "CNLiveMapDetailViewController.h" | |
| 11 | 12 | #import <CNLiveManager/CNLiveManager.h> |
| 12 | 13 | |
| 13 | 14 | @BeeHiveService(CNLiveSendPositionProtocol,CNLiveSendPositonService) |
| ... | ... | @@ -16,10 +17,6 @@ |
| 16 | 17 | @end |
| 17 | 18 | @implementation CNLiveSendPositonService |
| 18 | 19 | |
| 19 | -- (nonnull UIViewController *)getMapDetailViewController { | |
| 20 | - return nil; | |
| 21 | -} | |
| 22 | - | |
| 23 | 20 | - (void)pushToMapDetailViewController { |
| 24 | 21 | |
| 25 | 22 | } |
| ... | ... | @@ -30,4 +27,12 @@ |
| 30 | 27 | [CNLivePageJumpManager pushViewController:vc]; |
| 31 | 28 | } |
| 32 | 29 | |
| 30 | +-(void)pushToMapDetailViewController:(id)delegate location:(CLLocationCoordinate2D)location image:(NSString *)img addressName:(NSArray *)arr{ | |
| 31 | + CNLiveMapDetailViewController *vc = [CNLiveMapDetailViewController new]; | |
| 32 | + vc.delegate = delegate; | |
| 33 | + vc.locationCoordinate = location; | |
| 34 | + vc.img = img; | |
| 35 | + vc.locationInfo = arr; | |
| 36 | + [CNLivePageJumpManager pushViewController:vc]; | |
| 37 | +} | |
| 33 | 38 | @end | ... | ... |
Example/CNLiveMapModule.xcodeproj/project.pbxproj
| ... | ... | @@ -66,7 +66,7 @@ |
| 66 | 66 | B40A0CC225F7A654646D49EF /* Pods-CNLiveMapModule_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CNLiveMapModule_Tests.release.xcconfig"; path = "Target Support Files/Pods-CNLiveMapModule_Tests/Pods-CNLiveMapModule_Tests.release.xcconfig"; sourceTree = "<group>"; }; |
| 67 | 67 | C90EE460E908C716971A6DEA /* Pods-CNLiveMapModule_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CNLiveMapModule_Tests.debug.xcconfig"; path = "Target Support Files/Pods-CNLiveMapModule_Tests/Pods-CNLiveMapModule_Tests.debug.xcconfig"; sourceTree = "<group>"; }; |
| 68 | 68 | DB7AC79F3E7A256B51893001 /* libPods-CNLiveMapModule_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CNLiveMapModule_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 69 | - EEA4CF5F7EFD2DB95B91CC94 /* CNLiveMapModule.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CNLiveMapModule.podspec; path = ../CNLiveMapModule.podspec; sourceTree = "<group>"; }; | |
| 69 | + EEA4CF5F7EFD2DB95B91CC94 /* CNLiveMapModule.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CNLiveMapModule.podspec; path = ../CNLiveMapModule.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; | |
| 70 | 70 | /* End PBXFileReference section */ |
| 71 | 71 | |
| 72 | 72 | /* Begin PBXFrameworksBuildPhase section */ |
| ... | ... | @@ -512,7 +512,7 @@ |
| 512 | 512 | GCC_PREFIX_HEADER = "CNLiveMapModule/CNLiveMapModule-Prefix.pch"; |
| 513 | 513 | INFOPLIST_FILE = "CNLiveMapModule/CNLiveMapModule-Info.plist"; |
| 514 | 514 | MODULE_NAME = ExampleApp; |
| 515 | - PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; | |
| 515 | + PRODUCT_BUNDLE_IDENTIFIER = com.cnlive.CNLiveNetAdd.debug; | |
| 516 | 516 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 517 | 517 | SWIFT_VERSION = 4.0; |
| 518 | 518 | WRAPPER_EXTENSION = app; |
| ... | ... | @@ -529,7 +529,7 @@ |
| 529 | 529 | GCC_PREFIX_HEADER = "CNLiveMapModule/CNLiveMapModule-Prefix.pch"; |
| 530 | 530 | INFOPLIST_FILE = "CNLiveMapModule/CNLiveMapModule-Info.plist"; |
| 531 | 531 | MODULE_NAME = ExampleApp; |
| 532 | - PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; | |
| 532 | + PRODUCT_BUNDLE_IDENTIFIER = com.cnlive.CNLiveNetAdd.debug; | |
| 533 | 533 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 534 | 534 | SWIFT_VERSION = 4.0; |
| 535 | 535 | WRAPPER_EXTENSION = app; | ... | ... |
Example/CNLiveMapModule/CNLIVEViewController.m
| ... | ... | @@ -10,8 +10,10 @@ |
| 10 | 10 | #import "CNLiveServices.h" |
| 11 | 11 | #import "CNLiveMapViewController.h" |
| 12 | 12 | #import <MapKit/MapKit.h> |
| 13 | -@interface CNLIVEViewController ()<CNLiveSendPositonDelegate> | |
| 14 | - | |
| 13 | +@interface CNLIVEViewController ()<CNLiveMapPositionDelegate> | |
| 14 | +@property (nonatomic, assign)CLLocationCoordinate2D templocation; | |
| 15 | +@property (nonatomic, copy) NSString *tempImg; | |
| 16 | +@property (nonatomic, strong) NSArray *tempArr; | |
| 15 | 17 | @end |
| 16 | 18 | |
| 17 | 19 | @implementation CNLIVEViewController |
| ... | ... | @@ -25,11 +27,22 @@ |
| 25 | 27 | btn.frame = CGRectMake(100, 100, 100, 100); |
| 26 | 28 | [self.view addSubview:btn]; |
| 27 | 29 | [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside]; |
| 30 | + | |
| 31 | + UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 32 | + btn1.backgroundColor = [UIColor redColor]; | |
| 33 | + btn1.frame = CGRectMake(100, 100+200, 100, 100); | |
| 34 | + [self.view addSubview:btn1]; | |
| 35 | + [btn1 addTarget:self action:@selector(btnAction1) forControlEvents:UIControlEventTouchUpInside]; | |
| 28 | 36 | } |
| 29 | 37 | |
| 30 | 38 | - (void)btnAction{ |
| 31 | - id<CNLiveSendPositionProtocol> sendPositionP = [[BeeHive shareInstance] createService:@protocol(CNLiveSendPositionProtocol)]; | |
| 32 | - [sendPositionP pushToMapViewController:self]; | |
| 39 | + id<CNLiveSendPositionProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveSendPositionProtocol)]; | |
| 40 | + [service pushToMapViewController:self]; | |
| 41 | +} | |
| 42 | + | |
| 43 | +- (void)btnAction1{ | |
| 44 | + id<CNLiveSendPositionProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveSendPositionProtocol)]; | |
| 45 | + [service pushToMapDetailViewController:self location:self.templocation image:self.tempImg addressName:self.tempArr]; | |
| 33 | 46 | } |
| 34 | 47 | - (void)didReceiveMemoryWarning |
| 35 | 48 | { |
| ... | ... | @@ -39,6 +52,14 @@ |
| 39 | 52 | |
| 40 | 53 | - (void)sendCurrentLocation:(CLLocationCoordinate2D)location image:(nonnull NSString *)img addressName:(nonnull NSArray *)arr { |
| 41 | 54 | NSLog(@""); |
| 55 | + self.templocation = location; | |
| 56 | + self.tempImg = img; | |
| 57 | + self.tempArr = arr; | |
| 58 | + | |
| 59 | +} | |
| 60 | + | |
| 61 | +-(void)forwardingLocation:(CLLocationCoordinate2D)location image:(NSString *)img addressName:(NSArray *)arr{ | |
| 62 | + NSLog(@""); | |
| 42 | 63 | } |
| 43 | 64 | |
| 44 | 65 | @end | ... | ... |
Example/CNLiveMapModule/CNLiveMapModule-Info.plist
| ... | ... | @@ -22,8 +22,84 @@ |
| 22 | 22 | <string>????</string> |
| 23 | 23 | <key>CFBundleVersion</key> |
| 24 | 24 | <string>1.0</string> |
| 25 | + <key>LSApplicationQueriesSchemes</key> | |
| 26 | + <array> | |
| 27 | + <string>CNLiveNetAddProUrlSchemsZS</string> | |
| 28 | + <string>openapp.jdmobile</string> | |
| 29 | + <string>jdlogin</string> | |
| 30 | + <string>baidumap</string> | |
| 31 | + <string>iosamap</string> | |
| 32 | + <string>qqmap</string> | |
| 33 | + <string>wechat</string> | |
| 34 | + <string>weixin</string> | |
| 35 | + <string>mqqapi</string> | |
| 36 | + <string>mqq</string> | |
| 37 | + <string>mqqOpensdkSSoLogin</string> | |
| 38 | + <string>mqqconnect</string> | |
| 39 | + <string>mqqopensdkdataline</string> | |
| 40 | + <string>mqqopensdkgrouptribeshare</string> | |
| 41 | + <string>mqqopensdkfriend</string> | |
| 42 | + <string>mqqopensdkapi</string> | |
| 43 | + <string>mqqopensdkapiV2</string> | |
| 44 | + <string>mqqopensdkapiV3</string> | |
| 45 | + <string>mqqopensdkapiV4</string> | |
| 46 | + <string>mqzoneopensdk</string> | |
| 47 | + <string>wtloginmqq</string> | |
| 48 | + <string>wtloginmqq2</string> | |
| 49 | + <string>mqqwpa</string> | |
| 50 | + <string>mqzone</string> | |
| 51 | + <string>mqzonev2</string> | |
| 52 | + <string>mqzoneshare</string> | |
| 53 | + <string>wtloginqzone</string> | |
| 54 | + <string>mqzonewx</string> | |
| 55 | + <string>mqzoneopensdkapiV2</string> | |
| 56 | + <string>mqzoneopensdkapi19</string> | |
| 57 | + <string>mqzoneopensdkapi</string> | |
| 58 | + <string>mqqbrowser</string> | |
| 59 | + <string>mttbrowser</string> | |
| 60 | + <string>tim</string> | |
| 61 | + <string>timapi</string> | |
| 62 | + <string>timopensdkfriend</string> | |
| 63 | + <string>timwpa</string> | |
| 64 | + <string>timgamebindinggroup</string> | |
| 65 | + <string>timapiwallet</string> | |
| 66 | + <string>timOpensdkSSoLogin</string> | |
| 67 | + <string>wtlogintim</string> | |
| 68 | + <string>timopensdkgrouptribeshare</string> | |
| 69 | + <string>timopensdkapiV4</string> | |
| 70 | + <string>timgamebindinggroup</string> | |
| 71 | + <string>timopensdkdataline</string> | |
| 72 | + <string>wtlogintimV1</string> | |
| 73 | + <string>timapiV1</string> | |
| 74 | + <string>alipay</string> | |
| 75 | + <string>uppaysdk</string> | |
| 76 | + <string>uppaywallet</string> | |
| 77 | + <string>uppayx1</string> | |
| 78 | + <string>uppayx2</string> | |
| 79 | + <string>uppayx3</string> | |
| 80 | + <string>sinaweibohd</string> | |
| 81 | + <string>sinaweibo</string> | |
| 82 | + <string>sinaweibosso</string> | |
| 83 | + <string>weibosdk</string> | |
| 84 | + <string>weibosdk2.5</string> | |
| 85 | + </array> | |
| 25 | 86 | <key>LSRequiresIPhoneOS</key> |
| 26 | 87 | <true/> |
| 88 | + <key>NSAppTransportSecurity</key> | |
| 89 | + <dict> | |
| 90 | + <key>NSAllowsArbitraryLoads</key> | |
| 91 | + <true/> | |
| 92 | + </dict> | |
| 93 | + <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> | |
| 94 | + <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 95 | + <key>NSLocationAlwaysUsageDescription</key> | |
| 96 | + <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 97 | + <key>NSLocationWhenInUseUsageDescription</key> | |
| 98 | + <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 99 | + <key>UIBackgroundModes</key> | |
| 100 | + <array> | |
| 101 | + <string>location</string> | |
| 102 | + </array> | |
| 27 | 103 | <key>UILaunchStoryboardName</key> |
| 28 | 104 | <string>LaunchScreen</string> |
| 29 | 105 | <key>UIMainStoryboardFile</key> | ... | ... |