// // MapViewController.m // IBOSS // // Created by Dongke on 15/11/12. // Copyright © 2015年 elongtian. All rights reserved. // #import "MapViewController.h" //#import //#import //#import //#import "LogAddViewController.h" //#define APIKey @"3aac0809c410a4ba37b3065c7de8f90c"//2019-05-27 替换高德地图(yesen) ////@"1d883aa7c351032e715308700fba681d"//@"95ed2da3e9f4ece6319afbc437fc0b01" //#define kDefaultLocationZoomLevel 16.1 //#define kDefaultControlMargin 22 @interface MapViewController () // @end @implementation MapViewController{ // MAMapView* mapview; // AMapSearchAPI* search; // CLLocation* currentLocation; // UIButton* locationBtn; // UITableView* tableViewMap; // NSArray* pois; // NSMutableArray* annotations; // BOOL initLocationSearchFlg; } //- (void)viewDidLoad { // [super viewDidLoad]; // initLocationSearchFlg=NO; // [self initMapView]; // [self initControls]; // [self initAttributes]; // [self initTableView]; // [self initSearch]; // [self locateAction]; //} // //- (void)didReceiveMemoryWarning { // [super didReceiveMemoryWarning]; // // Dispose of any resources that can be recreated. //} ///** // 安全区改变 // */ //-(void)viewSafeAreaInsetsDidChange{ // tableViewMap.frame=CGRectMake(0, CGRectGetMaxY(mapview.frame), CGRectGetWidth(self.view.safeAreaLayoutGuide.layoutFrame), self.view.safeAreaLayoutGuide.layoutFrame.size.height -CGRectGetMaxY(mapview.frame)); // [super viewSafeAreaInsetsDidChange]; //} //-(void) initMapView{ // [AMapServices sharedServices].apiKey=APIKey; // mapview=[[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), (self.view.bounds.size.height) * 0.5+40)]; // mapview.delegate=self; // mapview.compassOrigin= CGPointMake(mapview.compassOrigin.x // , kDefaultControlMargin); // mapview.scaleOrigin=CGPointMake(mapview.scaleOrigin.x, kDefaultControlMargin); // [self.view addSubview:mapview]; // mapview.showsUserLocation=YES; //} // //- (void)initSearch //{ // //search = [[AMapSearchAPI alloc] initWithSearchKey:APIKey Delegate:self]; // //初始化检索对象 // search = [[AMapSearchAPI alloc] init]; // search.delegate = self; //} // //- (void)initControls //{ // self.navigationItem.title=@"请选择地理位置"; // UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"] // forState:UIControlStateNormal]; // [button addTarget:self action:@selector(goBack) // forControlEvents:UIControlEventTouchUpInside]; // button.frame = CGRectMake(0, 0, 15, 18); // // UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; // self.navigationItem.leftBarButtonItem = menuButton; //} // //- (void)initAttributes //{ // annotations = [NSMutableArray array]; // pois = [NSMutableArray array]; //} // //- (void)initTableView //{ // CGFloat halfHeight = CGRectGetHeight(self.view.bounds) * 0.5-23; // tableViewMap = [[UITableView alloc] initWithFrame:CGRectMake(0, halfHeight-20, CGRectGetWidth(self.view.bounds), halfHeight) style:UITableViewStylePlain]; // tableViewMap.delegate = self; // tableViewMap.dataSource = self; // // [self.view addSubview:tableViewMap]; //} // //#pragma mark - Helpers // //-(void)goBack //{ // [self.navigationController popViewControllerAnimated:YES]; //} // //-(void)searchAction{ // if (currentLocation == nil || search == nil) // { // NSLog(@"search failed"); // return; // } // // [AMapServices sharedServices].apiKey = APIKey; // //构造AMapPOIAroundSearchRequest对象,设置周边请求参数 // AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init]; // request.location=[AMapGeoPoint locationWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];; // request.keywords = @"商务住宅"; // // types属性表示限定搜索POI的类别,默认为:餐饮服务|商务住宅|生活服务 // // POI的类型共分为20种大类别,分别为: // // 汽车服务|汽车销售|汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务| // // 医疗保健服务|住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务| // // 交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施 // //     request.types = @"餐饮服务|生活服务"; // request.sortrule = 0; // request.requireExtension = YES; // //发起周边搜索 // [search AMapPOIAroundSearch: request]; //} // //- (void)locateAction //{ // if (mapview.userTrackingMode != MAUserTrackingModeFollow) // { // mapview.userTrackingMode = MAUserTrackingModeFollow; // [mapview setZoomLevel:kDefaultLocationZoomLevel animated:YES]; // // } // //} // //- (void)reGeoAction //{ // if (currentLocation) // { // AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init]; // // request.location = [AMapGeoPoint locationWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude]; // // [search AMapReGoecodeSearch:request]; // } //} // //#pragma mark - AMapSearchDelegate //- (void)searchRequest:(id)request didFailWithError:(NSError *)error //{ // NSLog(@"request :%@, error :%@", request, error); //} //-(void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response{ // NSLog(@"request: %@", request); // NSLog(@"response: %@", response); // // if (response.pois.count > 0) // { // pois = response.pois; // // [tableViewMap reloadData]; // // // 清空标注 // [mapview removeAnnotations:annotations]; // [annotations removeAllObjects]; // } //} // //-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{ // NSLog(@"response :%@", response); // // NSString *title = response.regeocode.addressComponent.city; // if (title.length == 0) // { // // 直辖市的city为空,取province // title = response.regeocode.addressComponent.province; // } // // // 更新我的位置title // mapview.userLocation.title = title; // mapview.userLocation.subtitle = response.regeocode.formattedAddress; //} // //#pragma mark - MAMapViewDelegate //-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation{ // if ([annotation isKindOfClass:[MAPointAnnotation class]]) // { // static NSString *reuseIndetifier = @"annotationReuseIndetifier"; // MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier]; // if (annotationView == nil) // { // annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier]; // } // annotationView.canShowCallout = YES; // // return annotationView; // } // return nil; //} //-(void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{ // if([view.annotation isKindOfClass:[MAUserLocation class]]){ // [self reGeoAction]; // } //} //-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{ // currentLocation=[userLocation.location copy]; // if(initLocationSearchFlg==NO){ // [self searchAction]; // } // initLocationSearchFlg=YES; //} //-(void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{ // // 修改定位按钮状态 // if (mode == MAUserTrackingModeNone) // { // [locationBtn setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal]; // } // else // { // [locationBtn setImage:[UIImage imageNamed:@"location_yes"] forState:UIControlStateNormal]; // // } // //} //#pragma mark -tableview //-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // return pois.count; //} //-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // static NSString *cellIdentifier = @"cellIdentifier"; // // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; // // if (cell == nil) // { // cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; // } // // AMapPOI *poi = pois[indexPath.row]; // // cell.textLabel.text = poi.name; // cell.detailTextLabel.text = poi.address; // // return cell; // //} //-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // // 为点击的poi点添加标注 // AMapPOI *poi = pois[indexPath.row]; // if ([self.pDelegate respondsToSelector:@selector(relocationData:)]) { // [self.pDelegate performSelector:@selector(relocationData:) withObject:poi.name]; // } // // [self.navigationController popViewControllerAnimated:YES]; // //} // //-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ // return 44; //} @end