| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- //
- // MapViewController.m
- // IBOSS
- //
- // Created by Dongke on 15/11/12.
- // Copyright © 2015年 elongtian. All rights reserved.
- //
- #import "MapViewController.h"
- //#import <AMapFoundationKit/AMapFoundationKit.h>
- //#import <MAMapKit/MAMapKit.h>
- //#import <AMapSearchKit/AMapSearchKit.h>
- //#import "LogAddViewController.h"
- //#define APIKey @"3aac0809c410a4ba37b3065c7de8f90c"//2019-05-27 替换高德地图(yesen)
- ////@"1d883aa7c351032e715308700fba681d"//@"95ed2da3e9f4ece6319afbc437fc0b01"
- //#define kDefaultLocationZoomLevel 16.1
- //#define kDefaultControlMargin 22
- @interface MapViewController ()
- //<MAMapViewDelegate,AMapSearchDelegate,UITableViewDataSource,UITableViewDelegate>
- @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<MAAnnotation>)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
|