iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 转到/缩放到当前位置功能(MapKit)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有一个mapView,它使用viewDidLoad缩放到当前位置: #define METERS_PER_MILE 1609.344 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super view
我有@L_791_1@mapView,它使用viewDidLoad缩放到当前位置:

#define METERS_PER_MILE 1609.344

// Implement viewDidLoad to do additional setup after loading the view,typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

    mapView.showsUserLOCATIOn=TRUE;

    // zoom to  a specific area
    CLLOCATIOnCoordinate2D zoomLOCATIOn;
    zoomLOCATIOn.latitude = -28.994167;
    zoomLOCATIOn.longitude = 134.866944;

    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLOCATIOn,1900*METERS_PER_MILE,1900*METERS_PER_MILE);
    MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];    

    // make sure the Google water mark is always visible
    mapView.autoresizingMask =
    (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

    [mapView setRegion:adjustedRegion animated:YES];        

    mapView.delegate=self;

    searchBar.delegate = self;
}

这很好用.我添加一个搜索栏和一个跳转到特定地址位置的函数.这也很好.我现在想要添加一个按钮来跳回当前位置.你可以帮我一把吗?

干杯

解决方法

您需要将地图的中心设置为点按该按钮的当前位置.说,像这样:

- (IBACtion)showCurrentLOCATIOn {        
    [mapView setCenterCoordinate:mapView.userLOCATIOn.LOCATIOn.coordinate animated:YES];
}

大佬总结

以上是大佬教程为你收集整理的iphone – 转到/缩放到当前位置功能(MapKit)全部内容,希望文章能够帮你解决iphone – 转到/缩放到当前位置功能(MapKit)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。