放大用户位置 - Swift

Posted

技术标签:

【中文标题】放大用户位置 - Swift【英文标题】:Zoom in on User Location- Swift 【发布时间】:2015-09-11 11:43:30 【问题描述】:

我不知道如何让地图从 viewDidLoad 放大用户位置。我尝试设置一个区域,但没有奏效。这是我的代码,有什么提示吗?

@IBOutlet 弱 var mapView: MKMapView! var MapViewLocationManager:CLLocationManager! = CLLocationManager() var currentLocation:PFGeoPoint! = PFGeoPoint()

override func viewDidLoad() 
    super.viewDidLoad()
    self.mapView.showsUserLocation = true
    mapView.delegate = self
   MapViewLocationManager.delegate = self
    mapView.setUserTrackingMode(MKUserTrackingMode.Follow, animated: true)

我已经查找了这个问题的答案,但没有在 Swift 中找到答案,也没有找到真正有效的答案。谢谢!!

【问题讨论】:

【参考方案1】:

我会尝试这样的:

    let latitude:CLLocationDegrees = //insert latitutde

    let longitude:CLLocationDegrees = //insert longitude

    let latDelta:CLLocationDegrees = 0.05

    let lonDelta:CLLocationDegrees = 0.05

    let span = MKCoordinateSpanMake(latDelta, lonDelta)

    let location = CLLocationCoordinate2DMake(latitude, longitude)

    let region = MKCoordinateRegionMake(location, span)

    mapView.setRegion(region, animated: false)

我看到你说你尝试设置一个区域。也许尝试这样做。

【讨论】:

非常感谢!我想这就是我卡住的地方,我将如何定义用户位置的纬度和经度? @Caitlin 不客气!我在手机上,所以我无法解释,但如果视频没有帮助,请查看:youtu.be/pSjbMwR2A2U 和此:***.com/a/25698536。【参考方案2】:

在大多数应用中,都实现了“当前位置”按钮。一个简单的方法是这样的:

@IBAction func myLocationButtonTapped(_ sender: Any) 

    mapView.showsUserLocation = true
    mapView.setUserTrackingMode(.follow, animated: true)


一旦用户平移或缩放地图,跟踪就会停止。所以对我来说已经足够了。

【讨论】:

【参考方案3】:

你必须试试这个。 它会缩放地图。

let span = MKCoordinateSpanMake(0.050, 0.050)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 23.0225, longitude: 72.5714), span: span)
mapView.setRegion(region, animated: true)`

【讨论】:

如果您想放大更多,只需在垃圾邮件中使用较小的数字:let spam = MKCoordinateSpanMake(0.001, 0.001)【参考方案4】:
@IBOutlet weak var conscienceMap: MKMapView!

override func viewDidLoad() 
    super.viewDidLoad()
    conscienceMap.showsUserLocation = true
    conscienceMap.setUserTrackingMode(MKUserTrackingMode.follow, animated: true)

【讨论】:

请说明您的代码。仅包含代码的答案并不能很好地帮助他人学习。

以上是关于放大用户位置 - Swift的主要内容,如果未能解决你的问题,请参考以下文章

Objective C/Swift Pinch 放大区域

Swift:检查 UIWebView 是放大还是缩小

如何放大用户当前位置?

放大显示的当前用户位置

Swift 3:在 CollectionView 中选择时放大图像

核心位置 - 放大当前位置