123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // DistenceTooLongMapVC.m
- // jiaPei
- //
- // Created by apple on 2018/1/31.
- // Copyright © 2018年 JCZ. All rights reserved.
- //
- #import "DistenceTooLongMapVC.h"
- #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- @interface DistenceTooLongMapVC ()<BMKMapViewDelegate>
- {
- BMKMapView *_mapView;
- }
- @end
- @implementation DistenceTooLongMapVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = @"扫码位置";
- self.view.backgroundColor = backGroundColor;
- [self configNavigationBar];
- [self myInit];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [_mapView viewWillAppear];
- _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [_mapView viewWillDisappear];
- _mapView.delegate = nil; // 不用时,置nil
- }
- - (void)myInit {
-
- _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height*7/12.0)];
- _mapView.delegate = self;
- [self.view addSubview:_mapView];
-
-
- NSMutableArray *annotationArray = [NSMutableArray arrayWithCapacity:2];
-
- BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = CLLocationCoordinate2DMake(_lat1, _lng1);
- annotation.title = @"当前位置";
- annotation.subtitle = [NSString stringWithFormat:@"距离教室%@米",_distence];
- [_mapView addAnnotation:annotation];
- [annotationArray addObject:annotation];
-
- annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = CLLocationCoordinate2DMake(_lat2, _lng2);
- annotation.title = @"理论教室位置";
- annotation.subtitle = [NSString stringWithFormat:@"距离您%@米",_distence];
- [_mapView addAnnotation:annotation];
- [annotationArray addObject:annotation];
-
- //中间点
- annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = CLLocationCoordinate2DMake(_lat1/2.0 + _lat2/2.0, _lng1/2.0 + _lng2/2.0);
- annotation.title = [NSString stringWithFormat:@"距离%.1fkm",[_distence floatValue]/1000.0];
- // annotation.subtitle = [NSString stringWithFormat:@"距离%.1fkm",[_distence floatValue]/1000.0];
- [_mapView addAnnotation:annotation];
- [annotationArray addObject:annotation];
-
- [_mapView selectAnnotation:annotation animated:YES];
- _mapView.centerCoordinate = annotation.coordinate;
-
-
- [_mapView showAnnotations:annotationArray animated:NO];
- _mapView.zoomLevel = _mapView.zoomLevel - 0.55;
-
- CLLocationCoordinate2D coor[2] = {0};
- coor[0] = CLLocationCoordinate2DMake(_lat1, _lng1);
- coor[1] = CLLocationCoordinate2DMake(_lat2, _lng2);
- BMKPolyline* polyline = [BMKPolyline polylineWithCoordinates:coor count:2];
- [_mapView addOverlay:polyline];
-
-
-
- //地图下UI
- CGFloat y = kSize.height * 7/12.0 - 24;//剩余24的距离用来掩盖百度的logo
- CGFloat h = kSize.height * 5/12.0 - 40;
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h)];
- view.backgroundColor = backGroundColor;
- [self.view addSubview:view];
-
- [view addViewWithRect:CGRectMake(0, y, kSize.width, 1.0)];
-
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, kSize.width - 40, h - 60)];
- [label setText:@"说明:当前位置距离理论教室位置过远,请前往理论教室所在地扫描二维码签到。如果当前位置获取有误,已在理论教室,请点击“重新定位”重置当前位置后再次扫码签到,祝您学车愉快!" Font:FontTitle TextColor:[UIColor orangeColor]];
- label.numberOfLines = 0;
- [view addSubview:label];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, h - 60, kSize.width - 40, 40)];
- btn.backgroundColor = defGreen;
- [btn setTitle:@"重新定位" textColor:[UIColor whiteColor] font:FontLarger fotState:UIControlStateNormal];
- [btn borderColor:backGroundColor width:.3 cornorRadios:4];
- [btn target:self tag:1];
- [view addSubview:btn];
- }
- - (void)btnClick:(UIButton *)sender {
- if (sender.tag == 1) {
- if (self.skipMspBlock) {
- self.skipMspBlock();
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- //标注的代理
- -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
- BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
-
- if ([annotation.title isEqualToString:@"当前位置"]) {
- newAnnotationView.image = [UIImage imageNamed:@"location_now"];
- }
- if ([annotation.title isEqualToString:@"理论教室位置"]) {
- newAnnotationView.image = [UIImage imageNamed:@"location_target"];
- }
-
- if ([annotation.title containsString:@"距离"]) {
- newAnnotationView.image = [UIImage imageNamed:@""];
- }
- // 设置该标注点动画显示
- newAnnotationView.animatesDrop = NO;
- return newAnnotationView;
- }
- return nil;
- }
- //根据overlay生成对应的View
- - (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay
- {
- if ([overlay isKindOfClass:[BMKPolyline class]]) {
- BMKPolylineView *polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];
- polylineView.lineWidth = 1.6;
- polylineView.strokeColor = [UIColor redColor];
- return polylineView;
- }
- return nil;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|