百度地图个人小结

1.如何点击按钮放大和缩小地图?

在地图上创建两个按钮加上点击事件,点击事件中分别写上如下方法即可实现:

创建按钮:

//左边按钮UIButton*leftBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];leftBtn.frame=CGRectMake(SCREEN_WIDTH*0.6, SCREEN_HEIGHT*0.93,60,30);[leftBtn setBackgroundImage:[UIImageimageNamed:@"left_btn"] forState:UIControlStateNormal];[leftBtn addTarget:selfaction:@selector(leftBtnAction:) forControlEvents:UIControlEventTouchUpInside];[self.viewaddSubview:leftBtn];//右边按钮UIButton*rightBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];rightBtn.frame=CGRectMake(SCREEN_WIDTH*0.6+61, SCREEN_HEIGHT*0.93,60,30);[rightBtn setBackgroundImage:[UIImageimageNamed:@"right_btn"] forState:UIControlStateNormal];[rightBtn addTarget:selfaction:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];[self.viewaddSubview:rightBtn];实现点击事件:- (void)leftBtnAction:(UIButton*)btn{[_mapView setZoomLevel:_mapView.zoomLevel-3];//缩小地图}- (void)rightAction:(UIButton*)btn{[_mapView setZoomLevel:_mapView.zoomLevel+3];//放大地图}

2.当在地图上大头针要实现连续点击事件上时该怎么做?(百度地图大头针默认只能点击一次)

//实现连续点击[_mapView deselectAnnotation:view.annotationanimated:YES];

3.当我们想要获取手机屏幕上能看到的所有大头针的经纬度时该怎么做?

//当前屏幕中心点的经纬度CGFloatcenterLongitude =self.mapView.region.center.longitude;CGFloatcenterLatitude =self.mapView.region.center.latitude;//当前屏幕显示范围的经纬度CLLocationDegrees pointssLongitudeDelta =self.mapView.region.span.longitudeDelta;CLLocationDegrees pointssLatitudeDelta =self.mapView.region.span.latitudeDelta;//左上角CGFloatleftUpLong = centerLongitude - pointssLongitudeDelta/2.0;CGFloatleftUpLati = centerLatitude - pointssLatitudeDelta/2.0;//右上角CGFloatrightUpLong = centerLongitude + pointssLongitudeDelta/2.0;CGFloatrightUpLati = centerLatitude - pointssLatitudeDelta/2.0;//左下角CGFloatleftDownLong = centerLongitude - pointssLongitudeDelta/2.0;CGFloatleftDownlati = centerLatitude + pointssLatitudeDelta/2.0;//右下角CGFloatrightDownLong = centerLongitude + pointssLongitudeDelta/2.0;CGFloatrightDownLati = centerLatitude + pointssLatitudeDelta/2.0;NSLog(@"\n 左上  %f,%f---------\n 右上  %f,%f-------\n 左下  %f,%f----- \n 右下  %f,%f",leftUpLong,leftUpLati,rightUpLong,rightUpLati,leftDownLong,leftDownlati,rightDownLong,rightDownLati);

4,百度地图的一些基本设置:

//设置百度地图的等级[_mapView setZoomLevel:10];//是否显示比例尺mapView.showMapScaleBar=YES;//比例尺在地图上的位置mapView.mapScaleBarPosition=CGPointMake(10,mapView.frame.size.height-45);//地图是否支持旋转,系统默认是旋转的,即为YES,不想地图旋转设为NO_mapView.rotateEnabled=YES;//设定地图是否现显示3D楼块效果_mapView.buildingsEnabled=YES;

5.如何在地图上循环创建多个大头针?

//循环遍历数组,数组里面包含所有的经纬度for(AnnotaionModel *modelin_annotaionArray) {//判断当经纬度为0的时候不在地图上显示if([model.LatitudedoubleValue]==0||[model.LongitudedoubleValue]==0) {continue;}_annotion = [[BMKPointAnnotationalloc]init];CLLocationCoordinate2D coor = CLLocationCoordinate2DMake([model.LatitudedoubleValue]  , [model.LongitudedoubleValue]);_annotion.coordinate= coor;[_mapView addAnnotation:_annotion];}

6.当你不想用系统的大头针,想用自己设置的图片来显示大头针时怎么做?

#pragma mark --BMKMapViewDelegate百度地图代理方法---- (BMKAnnotationView*)mapView:(BMKMapView*)mapView viewForAnnotation:(id)annotation{BMKPinAnnotationView*newAnnotationView = [[BMKPinAnnotationViewalloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];newAnnotationView.pinColor= BMKPinAnnotationColorPurple;for(AnnotaionModel *modelin_annotaionArray) {//设置大头针图片newAnnotationView.image= [UIImageimageNamed:@"icon_stop"];//当设为YES时view被选中时会弹出气泡,annotation必须实现了title这个方法,当为NO时点击大头针不会弹出气泡newAnnotationView.canShowCallout=NO;returnnewAnnotationView;}

7.如何获取自身定位的经纬度:

#pragma mark --BMKLocationServiceDelegate百度地图定位代理方法--- (void)didUpdateBMKUserLocation:(BMKUserLocation*)userLocation{CLLocationCoordinate2D coor = CLLocationCoordinate2DMake(userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude);NSLog(@"%f,%f",coor.latitude,coor.longitude);}

8.如何实现定位?

//自iOS SDK v2.5.0起,为了对iOS8的定位能力做兼容,做了相应的修改,开发者在使用过程中注意事项如下: 需要在info.plist里添加(以下二选一,两个都添加默认使用NSLocationWhenInUseUsageDescription):NSLocationWhenInUseUsageDescription,允许在前台使用时获取GPS的描述NSLocationAlwaysUsageDescription,允许永久使用GPS的描述_locationService = [[BMKLocationServicealloc]init];_locationService.delegate=self;//设置代理[_locationService startUserLocationService];//实现定位的代理方法#pragma mark ----BMKLocationServiceDelegate---- (void)didUpdateBMKUserLocation:(BMKUserLocation*)userLocation{CLLocationCoordinate2D coor = CLLocationCoordinate2DMake(userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude);_mapView.centerCoordinate= coor;[_mapView updateLocationData:userLocation];}

你可能感兴趣的:(百度地图个人小结)