【问题标题】:How can I zoom to certain coordinates in Swift 3 (Xcode 8)? [closed]如何在 Swift 3 (Xcode 8) 中缩放到某些坐标? [关闭]
【发布时间】:2018-04-23 04:21:22
【问题描述】:

我正在尝试使用坐标缩放到某个位置。 我怎样才能做到这一点?

【问题讨论】:

  • 你说的是地图视图吗?您是说您有一个纬度/经度地图坐标,并且您想将地图缩放到该点吗?你需要更清楚、更具体。

标签: ios swift3 xcode8


【解决方案1】:
import UIKit
import MapKit

class HomeViewController: UIViewController, MKMapViewDelegate {

@IBOutlet weak var mapView: MKMapView!

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.showsUserLocation = true


    if let userLocation = mapView.userLocation.location {
        //let frontedUserLocation = CLLocationCoordinate2DMake(37.7857, -122.4021)
        mapView.centerCoordinate = userLocation.coordinate
        //mapView.centerCoordinate = frontedUserLocation
        //let region = MKCoordinateRegionMakeWithDistance(frontedUserLocation, 1855, 1855)
        let region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 9484.1, 9484.1)
        mapView.setRegion(region, animated: true)
    }
    mapView.delegate = self
}

【讨论】:

    猜你喜欢
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多