小编典典

Swift iOS Google Map,协调路径

swift

我正在尝试在我的应用程序中创建一个函数,该函数将引导用户使用我创建的标记。这是我正在使用的代码,效果很好,它可以为用户提供当前位置并将其显示在地图上。但是,如何获得指向标记的说明?

任何遮篷都会有帮助

class Karta: UIViewController, CLLocationManagerDelegate {
    @IBOutlet var mapView: GMSMapView!

    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        //allow app to track user
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()

        //set out a marker on the map
        var marker = GMSMarker()
        marker.position = CLLocationCoordinate2DMake(56.675907, 12.858798)
        marker.appearAnimation = kGMSMarkerAnimationPop
        marker.icon = UIImage(named: "flag_icon")
        marker.map = mapView
     }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "Types Segue" {
            let navigationController = segue.destinationViewController as UINavigationController
        }
    }

    func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {

        //If map is being used
        if status == .AuthorizedWhenInUse {
            var myLocation = mapView
            locationManager.startUpdatingLocation()
            mapView.myLocationEnabled = true
            mapView.settings.myLocationButton = true
        }
    }

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
        if let location = locations.first as? CLLocation {
            mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
          locationManager.stopUpdatingLocation()
        }
    }
}

阅读 295

收藏
2020-07-07

共1个答案

小编典典

与Apple的MapKit不同,iOS的Google Maps SDK本身并不包含执行路线计算的方法。

相反,您需要使用Google Directions
API:https :
//developers.google.com/maps/documentation/directions/。它是仅HTTP的API,并且Google到目前为止还没有提供任何SDK,但是您可以轻松地自己编写包装器,或者选择Github上可用的众多选项之一:

2020-07-07