MapViewController.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. //
  2. // MapViewController.m
  3. // IBOSS
  4. //
  5. // Created by Dongke on 15/11/12.
  6. // Copyright © 2015年 elongtian. All rights reserved.
  7. //
  8. #import "MapViewController.h"
  9. //#import <AMapFoundationKit/AMapFoundationKit.h>
  10. //#import <MAMapKit/MAMapKit.h>
  11. //#import <AMapSearchKit/AMapSearchKit.h>
  12. //#import "LogAddViewController.h"
  13. //#define APIKey @"3aac0809c410a4ba37b3065c7de8f90c"//2019-05-27 替换高德地图(yesen)
  14. ////@"1d883aa7c351032e715308700fba681d"//@"95ed2da3e9f4ece6319afbc437fc0b01"
  15. //#define kDefaultLocationZoomLevel 16.1
  16. //#define kDefaultControlMargin 22
  17. @interface MapViewController ()
  18. //<MAMapViewDelegate,AMapSearchDelegate,UITableViewDataSource,UITableViewDelegate>
  19. @end
  20. @implementation MapViewController{
  21. // MAMapView* mapview;
  22. // AMapSearchAPI* search;
  23. // CLLocation* currentLocation;
  24. // UIButton* locationBtn;
  25. // UITableView* tableViewMap;
  26. // NSArray* pois;
  27. // NSMutableArray* annotations;
  28. // BOOL initLocationSearchFlg;
  29. }
  30. //- (void)viewDidLoad {
  31. // [super viewDidLoad];
  32. // initLocationSearchFlg=NO;
  33. // [self initMapView];
  34. // [self initControls];
  35. // [self initAttributes];
  36. // [self initTableView];
  37. // [self initSearch];
  38. // [self locateAction];
  39. //}
  40. //
  41. //- (void)didReceiveMemoryWarning {
  42. // [super didReceiveMemoryWarning];
  43. // // Dispose of any resources that can be recreated.
  44. //}
  45. ///**
  46. // 安全区改变
  47. // */
  48. //-(void)viewSafeAreaInsetsDidChange{
  49. // tableViewMap.frame=CGRectMake(0, CGRectGetMaxY(mapview.frame), CGRectGetWidth(self.view.safeAreaLayoutGuide.layoutFrame), self.view.safeAreaLayoutGuide.layoutFrame.size.height -CGRectGetMaxY(mapview.frame));
  50. // [super viewSafeAreaInsetsDidChange];
  51. //}
  52. //-(void) initMapView{
  53. // [AMapServices sharedServices].apiKey=APIKey;
  54. // mapview=[[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), (self.view.bounds.size.height) * 0.5+40)];
  55. // mapview.delegate=self;
  56. // mapview.compassOrigin= CGPointMake(mapview.compassOrigin.x
  57. // , kDefaultControlMargin);
  58. // mapview.scaleOrigin=CGPointMake(mapview.scaleOrigin.x, kDefaultControlMargin);
  59. // [self.view addSubview:mapview];
  60. // mapview.showsUserLocation=YES;
  61. //}
  62. //
  63. //- (void)initSearch
  64. //{
  65. // //search = [[AMapSearchAPI alloc] initWithSearchKey:APIKey Delegate:self];
  66. // //初始化检索对象
  67. // search = [[AMapSearchAPI alloc] init];
  68. // search.delegate = self;
  69. //}
  70. //
  71. //- (void)initControls
  72. //{
  73. // self.navigationItem.title=@"请选择地理位置";
  74. // UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  75. // [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
  76. // forState:UIControlStateNormal];
  77. // [button addTarget:self action:@selector(goBack)
  78. // forControlEvents:UIControlEventTouchUpInside];
  79. // button.frame = CGRectMake(0, 0, 15, 18);
  80. //
  81. // UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  82. // self.navigationItem.leftBarButtonItem = menuButton;
  83. //}
  84. //
  85. //- (void)initAttributes
  86. //{
  87. // annotations = [NSMutableArray array];
  88. // pois = [NSMutableArray array];
  89. //}
  90. //
  91. //- (void)initTableView
  92. //{
  93. // CGFloat halfHeight = CGRectGetHeight(self.view.bounds) * 0.5-23;
  94. // tableViewMap = [[UITableView alloc] initWithFrame:CGRectMake(0, halfHeight-20, CGRectGetWidth(self.view.bounds), halfHeight) style:UITableViewStylePlain];
  95. // tableViewMap.delegate = self;
  96. // tableViewMap.dataSource = self;
  97. //
  98. // [self.view addSubview:tableViewMap];
  99. //}
  100. //
  101. //#pragma mark - Helpers
  102. //
  103. //-(void)goBack
  104. //{
  105. // [self.navigationController popViewControllerAnimated:YES];
  106. //}
  107. //
  108. //-(void)searchAction{
  109. // if (currentLocation == nil || search == nil)
  110. // {
  111. // NSLog(@"search failed");
  112. // return;
  113. // }
  114. //
  115. // [AMapServices sharedServices].apiKey = APIKey;
  116. // //构造AMapPOIAroundSearchRequest对象,设置周边请求参数
  117. // AMapPOIAroundSearchRequest *request = [[AMapPOIAroundSearchRequest alloc] init];
  118. // request.location=[AMapGeoPoint locationWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];;
  119. // request.keywords = @"商务住宅";
  120. // // types属性表示限定搜索POI的类别,默认为:餐饮服务|商务住宅|生活服务
  121. // // POI的类型共分为20种大类别,分别为:
  122. // // 汽车服务|汽车销售|汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|
  123. // // 医疗保健服务|住宿服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|
  124. // // 交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施
  125. // //     request.types = @"餐饮服务|生活服务";
  126. // request.sortrule = 0;
  127. // request.requireExtension = YES;
  128. // //发起周边搜索
  129. // [search AMapPOIAroundSearch: request];
  130. //}
  131. //
  132. //- (void)locateAction
  133. //{
  134. // if (mapview.userTrackingMode != MAUserTrackingModeFollow)
  135. // {
  136. // mapview.userTrackingMode = MAUserTrackingModeFollow;
  137. // [mapview setZoomLevel:kDefaultLocationZoomLevel animated:YES];
  138. //
  139. // }
  140. //
  141. //}
  142. //
  143. //- (void)reGeoAction
  144. //{
  145. // if (currentLocation)
  146. // {
  147. // AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init];
  148. //
  149. // request.location = [AMapGeoPoint locationWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
  150. //
  151. // [search AMapReGoecodeSearch:request];
  152. // }
  153. //}
  154. //
  155. //#pragma mark - AMapSearchDelegate
  156. //- (void)searchRequest:(id)request didFailWithError:(NSError *)error
  157. //{
  158. // NSLog(@"request :%@, error :%@", request, error);
  159. //}
  160. //-(void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response{
  161. // NSLog(@"request: %@", request);
  162. // NSLog(@"response: %@", response);
  163. //
  164. // if (response.pois.count > 0)
  165. // {
  166. // pois = response.pois;
  167. //
  168. // [tableViewMap reloadData];
  169. //
  170. // // 清空标注
  171. // [mapview removeAnnotations:annotations];
  172. // [annotations removeAllObjects];
  173. // }
  174. //}
  175. //
  176. //-(void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
  177. // NSLog(@"response :%@", response);
  178. //
  179. // NSString *title = response.regeocode.addressComponent.city;
  180. // if (title.length == 0)
  181. // {
  182. // // 直辖市的city为空,取province
  183. // title = response.regeocode.addressComponent.province;
  184. // }
  185. //
  186. // // 更新我的位置title
  187. // mapview.userLocation.title = title;
  188. // mapview.userLocation.subtitle = response.regeocode.formattedAddress;
  189. //}
  190. //
  191. //#pragma mark - MAMapViewDelegate
  192. //-(MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation{
  193. // if ([annotation isKindOfClass:[MAPointAnnotation class]])
  194. // {
  195. // static NSString *reuseIndetifier = @"annotationReuseIndetifier";
  196. // MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
  197. // if (annotationView == nil)
  198. // {
  199. // annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
  200. // }
  201. // annotationView.canShowCallout = YES;
  202. //
  203. // return annotationView;
  204. // }
  205. // return nil;
  206. //}
  207. //-(void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{
  208. // if([view.annotation isKindOfClass:[MAUserLocation class]]){
  209. // [self reGeoAction];
  210. // }
  211. //}
  212. //-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
  213. // currentLocation=[userLocation.location copy];
  214. // if(initLocationSearchFlg==NO){
  215. // [self searchAction];
  216. // }
  217. // initLocationSearchFlg=YES;
  218. //}
  219. //-(void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
  220. // // 修改定位按钮状态
  221. // if (mode == MAUserTrackingModeNone)
  222. // {
  223. // [locationBtn setImage:[UIImage imageNamed:@"location_no"] forState:UIControlStateNormal];
  224. // }
  225. // else
  226. // {
  227. // [locationBtn setImage:[UIImage imageNamed:@"location_yes"] forState:UIControlStateNormal];
  228. //
  229. // }
  230. //
  231. //}
  232. //#pragma mark -tableview
  233. //-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  234. // return pois.count;
  235. //}
  236. //-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  237. // static NSString *cellIdentifier = @"cellIdentifier";
  238. //
  239. // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  240. //
  241. // if (cell == nil)
  242. // {
  243. // cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
  244. // }
  245. //
  246. // AMapPOI *poi = pois[indexPath.row];
  247. //
  248. // cell.textLabel.text = poi.name;
  249. // cell.detailTextLabel.text = poi.address;
  250. //
  251. // return cell;
  252. //
  253. //}
  254. //-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  255. // // 为点击的poi点添加标注
  256. // AMapPOI *poi = pois[indexPath.row];
  257. // if ([self.pDelegate respondsToSelector:@selector(relocationData:)]) {
  258. // [self.pDelegate performSelector:@selector(relocationData:) withObject:poi.name];
  259. // }
  260. //
  261. // [self.navigationController popViewControllerAnimated:YES];
  262. //
  263. //}
  264. //
  265. //-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  266. // return 44;
  267. //}
  268. @end