如何找到用户与Google Map API IOS Swift上的标记的距离

问题描述 投票:0回答:1

我是Swift IOS开发的新手,我试图找出用户与每个标记之间的距离。我正在使用google maps api和distance函数,但是即时通讯无法正常工作。有谁知道为什么这不起作用以及我应该更改什么?

// Creates markers
func createMarkers() {
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: lat , longitude: long)
    marker.title = bar_name
    marker.map = mapView
    var userLocation = locationManager.location
    var meters = userLocation?.distance(from: CLLocation(latitude: marker.position.latitude, longitude: marker.position.longitude))
//        let meters = func distance(from CLLocation: CLLocation) -> CLLocation(latitude: marker.position.latitude, longitude: marker.position.longitude)
// I alternatively tried ^^ this commented line of code ^^ as well 
        print(meters!)
    }
ios swift distance google-maps-sdk-ios cllocation
1个回答
0
投票

尝试一下:

let coordinate0 = CLLocation(latitude: 5.0, longitude: 5.0)
let coordinate1 = CLLocation(latitude: 5.0, longitude: 3.0) 
let distanceInMeters = coordinate0.distance(from: coordinate1)
© www.soinside.com 2019 - 2024. All rights reserved.