내 응용 프로그램에 Google지도를 구현하려고했습니다. 첫 번째 단계는 내가 얻고 자하는 것입니다. 1. 앱에 현재 위치 사용 권한을 묻습니다. 2. 사용자의 현재 위치를 찾아 파란색 점 마커를 표시하여 표시합니다. 3. 사용자의 현재 위치를 중심으로지도를 업데이트하고 가운데 놓습니다.Xcode 용 Google지도 SDK의 현재 위치 업데이트가 작동하지 않습니다.
나는이 작업을하기 위해 다양한 방법을 시도했지만 항상 오류가 발생하거나 작동하지 않습니다. 처음에 아래 코드를 시뮬레이션했을 때 현재 위치 권한과 파란색 점을 요청하는 대화 상자가 표시되었지만 다음 시뮬레이션에서는 사라진 것처럼 보였습니다. 그리고 시뮬레이터에서 현재 위치를 변경할 때 (스키마를 수정하고 기본 위치), 새 현재 위치가 업데이트되지 않았습니다. 코드가 viewDidLoad 이상으로 작동하지 않는다는 느낌이 들었습니다. 나는 어디로 잘못 가고 있니?
이러한 문제를 수정하고 위의 사항이 작동하는 방법에 대한 조언을 얻을 수 있습니까? (시뮬레이터는 물론 현재 위치에 대한 권한을 요청할 수도 있습니다). 현재 코드는 오류없이 실행되지만 영국지도 만 보여줍니다.
import UIKit
import GoogleMaps
class FirstViewController: UIViewController,CLLocationManagerDelegate {
@IBOutlet weak var googlemaps: GMSMapView!
//this is the connection from the storyboard to the view controller
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 51.508742, longitude: -0.087891, zoom: 8.0)
let viewMap = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = viewMap
viewMap.isMyLocationEnabled = true
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
}
override func loadView() {
super.viewDidLoad()
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
// verification of granted permission while app in use
let locationManager = CLLocationManager()
let mapView = GMSMapView()
if status == .authorizedWhenInUse {
locationManager.startUpdatingLocation()
// if permission granted- starting updating location
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
//this is suppose to be button that is added when tapped centers to users location
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
mapView.camera = GMSCameraPosition.camera(withTarget: location.coordinate, zoom: 20)
self.view = mapView
locationManager.stopUpdatingLocation()
}
}
}
}
}
감사합니다 사전에 (. 나는 또한 시뮬레이터를 재설정 시도 나는 이미의 Info.plist에 NSLocationWhenInUse 및 NSLocationAlwaysUsage을 .... 추가했다. 그리고 나는 모든 중단 점을 비활성화 한)! (