【问题标题】:Way map tracker for MapKit or Google Maps [closed]MapKit 或谷歌地图的地图跟踪器[关闭]
【发布时间】:2018-02-26 18:32:38
【问题描述】:

有人有跟踪我使用 CoreLocation 的方式的经验。像这样:

如果有人有样品,请发给我链接。谢谢

【问题讨论】:

    标签: swift google-maps location mapkit core-location


    【解决方案1】:

    使用MKCircle,您可以轻松制作地图追踪器。

    import UIKit
    import MapKit
    
    class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate  {
    
        @IBOutlet weak var mapView: MKMapView!
        var locationManager: CLLocationManager!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            mapView.showsUserLocation = true
    
            if CLLocationManager.locationServicesEnabled() {
                locationManager = CLLocationManager()
                locationManager.delegate = self
                locationManager.desiredAccuracy = kCLLocationAccuracyBest
                locationManager.requestWhenInUseAuthorization()
                locationManager.startUpdatingLocation()
            }
        }
    
        // MARK: - MKMapView delegate
    
        func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
            let span = MKCoordinateSpanMake(0.01, 0.01)
            let region = MKCoordinateRegionMake(userLocation.coordinate, span)
            mapView.setRegion(region, animated:true)
    
            let center = userLocation.coordinate
            let circle = MKCircle(center: center, radius: 10)
            mapView.add(circle)
        }
    
        func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
            let circleRenderer : MKCircleRenderer = MKCircleRenderer(overlay: overlay);
            circleRenderer.fillColor = .blue
            circleRenderer.lineWidth = 1.0
            return circleRenderer
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      相关资源
      最近更新 更多