百度SDK的使用第一天

时间:2021-08-08 11:23:06

//获取自定义的经纬度上添加位置气泡,大头钉

BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];

CLLocationCoordinate2D coor;

coor.latitude = 39.915;

coor.longitude = 116.404;

annotation.coordinate = coor;

annotation.title = @"北京";

annotation.subtitle = @"这里是北京";

[_mapView addAnnotation:annotation];

//这样就可以在初始化的时候将 气泡信息弹出

//获取当前位置

[_mapView selectAnnotation:annotation animated:YES];

_mapView.showsUserLocation = YES;

CLLocationCoordinate2D coor1;

BMKUserLocation *userLocation =[[BMKUserLocation alloc] init];

if (userLocation.location != nil)

{

NSLog(@"定位成功");

coor1 = [[userLocation location] coordinate];

NSLog(@"%f",coor1.latitude);

NSLog(@"%f",coor1.longitude);

}

coor1 = [[userLocation location] coordinate];

BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(coor1, BMKCoordinateSpanMake(0.02f,0.02f));

BMKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];

[_mapView setRegion:adjustedRegion animated:YES];