您的位置:首页 > 移动开发 > IOS开发

ios 地图大头针固定在地图中心,用用地图中心点左边逆地理编码,及高德云图周边搜索

2015-11-12 15:48 549 查看
废话不多说,直接上代码:

一.添加一个点在地图中心,其实很简单,直接将一imageView添加到屏幕的中心就行了,注意的是在这之前先添加mapView,以免被覆盖

    UIImageView *imageView = [[UIImageView
alloc] initWithFrame:CGRectMake((SCREEN_WIDTH -
40) / 2, (SCREEN_HEIGHT -
60) / 2,
40, 60)];
    imageView.image = [UIImage
imageNamed:@"redPin_lift"];
    [self.view
addSubview:imageView];

二.在地图区域改变完成后的接口

- (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated
中获取地图中心点坐标

  - (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated
   { 
    MACoordinateRegion region;
    CLLocationCoordinate2D centerCoordinate = mapView.region.center;
    region.center = centerCoordinate;

   拿到中心点后,就随你怎么弄,为所欲为了................   我是用他来做逆地理编码后在地图上显示地址,和云图的周边搜索

三.显示逆地理编码的地址
    同一,在self.view上添加一个view,用于显示地址,用全局的

   _fixedView = [[CustomCalloutView
alloc] initWithFrame:CGRectMake((SCREEN_WIDTH -
120) / 2, (SCREEN_HEIGHT -
80) / 2 -
40, 120,
50)];
    [self.view
addSubview:_fixedView];

    _fixedTitleLabel = [[UILabel
alloc] init];
    _fixedTitleLabel.lineBreakMode =
NSLineBreakByCharWrapping;
    _fixedTitleLabel.numberOfLines =
0;
    [_fixedView
addSubview:_fixedTitleLabel];
  在地图区域即将改变的接口中先隐藏view,

  - (void)mapView:(MAMapView *)mapView regionWillChangeAnimated:(BOOL)animated
  {
    _fixedView.hidden =
YES;
  }
  在地图区域改变完成后的接口中再将它显示

  - (void)mapView:(MAMapView *)mapView regionDidChangeAnimated:(BOOL)animated
 {     _fixedView.hidden = NO;

四.对获得的中心点逆地理编码,成功后就地址给label显示出来
五.对获得的中心点,用云图的周边搜索

  [self
aroundSearchRequestWithCoordinate:centerCoordinate];
 搜索出的结果只需要addAnnotations就行了,不要再showAnnotations了,应为showAnnotations又会触发  - (void)mapView:(MAMapView *)mapView  regionDidChangeAnimated:(BOOL)animated;那样就bug了

总结:具体功能类似神州专车,如果不清楚需求可以去看看。第一次写博客,写得不太好,文中不妥之处,望多指教,不胜感激。如有疑问请联系QQ:1065885706
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 地图