android百度地图拖拽地图定位,百度地图 拖动时时定位

思路:

(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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值