/ / Swift, toma lugares cerca de la posición del usuario: ios, swift, xcode, google-maps

Swift, toma lugares cerca de la posición del usuario: ios, swift, xcode, google-maps

Soy un principiante en el desarrollo de un i. Estoy agregando un mapa de Google en una vista de mi aplicación. Siguiendo un tutorial, utilicé este código.

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)")
}

para encontrar la ubicación del usuario, ahora me gustaríavea en el mapa los lugares (lugares de Google) que están a una X distancia de la posición del usuario, ¿cómo puedo hacerlo? Busqué en el documento de Google Places pero no encontré una respuesta válida.

Respuestas

1 para la respuesta № 1

Agregue otro marcador en la pestaña MapView y haga que se pueda arrastrar y use CLLocationDistance para medir la distancia entre 2 ubicaciones.

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