/ / Swift, uskutočňujte miesta v blízkosti polohy používateľa - ios, swift, xcode, google-maps

Swift, miesta v blízkosti polohy užívateľa - ios, swift, xcode, google-maps

Som začiatočník vo vývoji a pridávam mapu Google na zobrazenie mojej aplikácie, po tutoriále som použil tento kód

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location: CLLocation = locations.last!
print("Location: (location)")

let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,
longitude: location.coordinate.longitude,
zoom: zoomlevel)


let marker = GMSMarker()
marker.title = "My Position"

marker.map = mapView
if mapView.isHidden {
mapView.isHidden = false
mapView.camera = camera
} else {
mapView.animate(to: camera)
}


}


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted:
print("Location access was restricted.")
case .denied:
print("User denied access to location.")

mapView.isHidden = false
case .notDetermined:
print("Location status not determined.")
case .authorizedAlways: fallthrough
case .authorizedWhenInUse:
print("Location status is OK.")
}
}


func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
locationManager.stopUpdatingLocation()
print("Error: (error)")
}

nájsť polohu používateľa, teraz by som chcelna mape vidím miesta (google miesta), ktoré sú vo vzdialenosti X od polohy používateľa, ako to môžem urobiť? Hľadal som v dokumente Miesta Google, ale nenašiel som platnú odpoveď

odpovede:

1 pre odpoveď č. 1

Pridajte ďalšiu značku onTap na mapView a urobte ju ťahateľnou a použite CLLocationDistance na meranie vzdialenosti medzi 2 miestami.

let distanceInMeters = self.locationManager.location?.distance(from: newMarkerLocation!)