本文转载自http://blog.csdn.net/fanjunxi1990/article/details/9131003
mapView.showsUserLocation = YES; if (mapView.userLocation.location != nil) { NSLog(@"定位成功"); coor = [[mapView.userLocation location] coordinate]; NSLog(@"%f",coor.latitude); NSLog(@"%f",coor.longitude); } BMKCoordinateRegion viewRegion = BMKCoordinateRegionMake(coor, BMKCoordinateSpanMake(0.02f,0.02f)); BMKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion]; [mapView setRegion:adjustedRegion animated:YES];
/** *用户位置更新后,会调用此函数 *@param mapView 地图View *@param userLocation 新的用户位置 */ - (void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation;
#pragma mark mapViewDelegate 代理方法 - (void)mapView:(BMKMapView *)mapView1 didUpdateUserLocation:(BMKUserLocation *)userLocation { BMKCoordinateRegion region; region.center.latitude = userLocation.location.coordinate.latitude; region.center.longitude = userLocation.location.coordinate.longitude; region.span.latitudeDelta = 0.2; region.span.longitudeDelta = 0.2; if (mapView) { mapView.region = region; NSLog(@"当前的坐标是: %f,%f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude); } }