放大用户位置

发布于 2024-08-24 21:38:19 字数 435 浏览 3 评论 0原文

如何在我的应用程序中自动缩放 userLocation 上的地图? 我有以下代码可以在地图中缩放,但我必须缩放用户位置,并且以下代码始终缩放到非洲?

MKCoordinateRegion zoomIn = mapView.region;
    zoomIn.span.latitudeDelta *= 0.2;
    zoomIn.span.longitudeDelta *= 0.2;
    zoomIn.center.latitude = mapView.userLocation.location.coordinate.latitude;
    zoomIn.center.longitude = mapView.userLocation.location.coordinate.longitude;
    [mapView setRegion:zoomIn animated:YES];

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.longitudeDelta *= 0.2;
    zoomIn.center.latitude = mapView.userLocation.location.coordinate.latitude;
    zoomIn.center.longitude = mapView.userLocation.location.coordinate.longitude;
    [mapView setRegion:zoomIn animated:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流绪微梦 2024-08-31 21:38:19

好的,我使用以下委托方法解决了问题:

-(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];
        }
    }
}

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];
        }
    }
}
北座城市 2024-08-31 21:38:19

非常感谢伙伴,这对我帮助很大。真的很想投票,但由于我的代表级别而不能投票。

我还发现使用:

mapView.userLocation.location.coordinate.latitude;

总是将我缩放到非洲,并且从未将我集中到当前位置。

但通过使用委托方法:

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

我能够成功解决这个问题。我发现当使用mapView.userLocation.location.coordinate.latitude;时viewDidLoad 方法中的视图启动时没有触发正确的用户坐标,因此它显示了错误的坐标。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文