Ответы пользователя по тегу Swift
  • Как узнать свои координаты в google maps?

    @sportredwhite Автор вопроса
    Нашёл ответ) надо использовать ещё и "import GooglePlaces"

    пример кода:
    placesClient = GMSPlacesClient()
            
            placesClient.currentPlace { (placeLikelihoodList, error) in
                if let error = error {
                    print("Pick Place error: \(error.localizedDescription)")
                    return
                }
                
                
                if let placeLicklihoodList = placeLikelihoodList {
                    let place = placeLicklihoodList.likelihoods.first?.place
                    if let place = place {
                        if self.longtitude == nil && self.lantitude == nil {
                            self.lantitude = place.coordinate.latitude
                            self.longtitude = place.coordinate.longitude
                            self.address = "\(place.formattedAddress!)"
                        } else {
                            self.geoCoder.geocodeAddressString(self.address, completionHandler: { (placemark, error) in
                                if error == nil {
                                    print(error?.localizedDescription ?? "Error")
                                }
                                
                                print(self.address)
                                
                                let location = placemark?[0].location?.coordinate
                                self.lantitude = location?.latitude
                                self.longtitude = location?.longitude
                                
                                print(self.lantitude)
                                print(self.longtitude)
                                
                            })
                        }
                    }
                }
        
                
                self.mapView = GMSMapView(frame: self.mapContainer.frame)
                let currentPosition = CLLocationCoordinate2D(latitude: self.lantitude, longitude: self.longtitude)
                self.mapView.camera = GMSCameraPosition(target: currentPosition, zoom: 15, bearing: 0, viewingAngle: 0)
                self.view.addSubview(self.mapView)
            }
    Ответ написан
    Комментировать