![](/img/trans.png)
[英]How to draw a route between my current location to desired location on MKMapView?
[英]How to center my current location in MKMapView?
我通过使用showUserLocation
启用在MKMapView
显示current location
。 我还想将mapview
集中到用户当前位置以及缩放的位置图。 请帮我解决这个问题,因为我在stackoverflow上没有得到任何其他类似问题的帮助。
我的代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
[mapView setDelegate:self];
}
要以用户位置为中心,您可以使用以下代码:
[mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES];
要放大特殊位置,您应该研究区域( MKCoordinateRegion
)的计数和工作方式,计算区域的值并使用调用显示它:
[mapView setRegion:myRegion animated:YES];
此示例WorldCities显示了区域显示的基础知识。
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.2; // 0.0 is min value u van provide for zooming
span.longitudeDelta= 0.2;
CLLocationCoordinate2D location = [self addressLocation];
region.span=span;
region.center =location; // to locate to the center
if(addAnnotation != nil) {
[mapView removeAnnotation:addAnnotation];
[addAnnotation release];
addAnnotation = nil;
}
addAnnotation = [[AddressANnotation alloc] initWithCoordinate:location];
[mapView addAnnotation:addAnnotation];
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
这有助于我在地图视图的中心显示位置。
对于MKMapView
self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MKUserTrackingModeFollow;
-(void) removeZoom:(float)deltaValue
{
MKCoordinateRegion region;
region.center.latitude = self.locationManager.location.coordinate.latitude;
region.center.longitude = self.locationManager.location.coordinate.longitude;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
region.span.latitudeDelta = deltaValue;
region.span.longitudeDelta = deltaValue;
region = [mapViewSelf regionThatFits:region];
[mapViewSelf setRegion:region animated:YES];
[UIView commitAnimations];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.