私は自分のアプリケーションでGoogleマップを実装しようとしています。私がしたい最初のステップは、簡単に取得することです: 1.現在の場所を使用する許可を求めるようにアプリを入手してください 2.ユーザーの現在の場所を探し、それをマークするための青い点のマーカーがあります。 3.ユーザーの現在地を中心に地図を更新し、中央に配置します。XcodeのGoogle Maps 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を....追加されました。そして、私はすべてのブレークポイントを無効にしています)! (