开发者

Zoom on userLocation

how can I zoom the map on my userLocation automatically in my app? I have the following code to zomm in the map but i must zoom on the userLocation and the following code zooms always to africa?

MKCoordinateRegion zoomIn = mapView.region;
    zoomIn.span.latitudeDelta *= 0.2;
    zoomIn.span.longitu开发者_如何学编程deDelta *= 0.2;
    zoomIn.center.latitude = mapView.userLocation.location.coordinate.latitude;
    zoomIn.center.longitude = mapView.userLocation.location.coordinate.longitude;
    [mapView setRegion:zoomIn animated:YES];


OK i solved the problem, with the following delegate Method:

-(void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views{
    for(MKAnnotationView *annotationView in views) {
        if(annotationView.annotation == mv.userLocation){
            MKCoordinateRegion region;
            MKCoordinateSpan span;

            span.latitudeDelta=0.9;
            span.longitudeDelta=0.9;

            CLLocationCoordinate2D location =mv.userLocation.coordinate;

            location = mv.userLocation.location.coordinate;

            region.span = span;
            region.center = location;
            [mv setRegion:region animated:TRUE];
            [mv regionThatFits:region];
        }
    }
}


thanks alot mate, this helped me greatly. Really wanted to vote but cant because of my rep level.

I also found that using:

mapView.userLocation.location.coordinate.latitude;

always zoomed me to africa, and never centered me onto my current location.

But by using the delegate method:

-(void)mapView:(MKMapView *)myMapView didAddAnnotationViews:(NSArray *)views {

I was able to solve this successfully. What I discovered is that when using mapView.userLocation.location.coordinate.latitude; in the viewDidLoad method wasn't triggering the correct user coords on startup of the view, hence it was displaying the wrong coords.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜