思路:
(1)把图片放到屏幕的中间,这样在拖动的时候就不会跟随着地图移动了。
(2)百度地图提供了,View坐标和地理坐标转换的方法。正式这个方法的存在,方便我们及时的获取拖动后的,屏幕中间的图片所在位置的经纬度。
代码如下:
@interface HomeViewController (){
BMKLocationService * _locService;
}
@property (nonatomic,strong) UIView * locationView;
@property (nonatomic,strong) UIImageView * locImageView;
@property (nonatomic,strong) UIView * messageView;
@property (nonatomic,strong) UILabel * addressLabel;
@property (nonatomic,strong) UIButton * sureButton;
@property (nonatomic,strong) NSString * name;
@property (nonatomic,assign) CLLocationCoordinate2D location2D;
@property (nonatomic, strong)BMKGeoCodeSearch *searchAddress;
@property (strong, nonatomic)BMKMapView *mapView;
@property (nonatomic,strong)BMKUserLocation *userLocation; //定位功能
@end
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setupDatasource];
[self setupNav];
[self setupViews];
[self setupGoBack];
}
-(void)setupDatasource {
}
-(void)setupNav {
self.title = @"首页";
self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"me" highImage:@"me" target:self action:@selector(goMe:)];
}
//跳转个人中心
-(void)goMe : (id)sender {
}
-(void)setupViews {
self.mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, YSWIDTH, YSHEIGHT - 64)];
self.mapView.delegate =self;
//设置地图的显示样式
self.mapView.mapType = BMKMapTypeStandard;//标准地图
//设定地图是否打开路况图层
self.mapView.trafficEnabled = YES;
//底图poi标注
self.mapView.showMapPoi = YES;
//在手机上当前可使用的级别为3-21级
self.mapView.zoomLevel = 21;
//设定地图View能否支持旋转
self.mapView.rotateEnabled = NO;
//设定地图View能否支持用户移动地图
self.mapView.scrollEnabled = YES;
//添加到view上
[self.view addSubview:self.mapView];
[self initlocationService];
}
-(void)setupGoBack {
UIButton *gobackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
gobackBtn.frame = CGRectMake(10, YSHEIGHT - 10 - 64 - 40, 40, 40);
gobackBtn.backgroundColor = [UIColor redColor];
[gobackBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[gobackBtn addTarget:self action:@selector(locationButtonClick:) forControlEvents:UIControlEventTouch