所以我試圖獲得它,所以我打開應用程序,它開始在用戶的位置。問題是我在輸出框中顯示「用戶位置未知」。我已經啓用了位置,如下面的代碼所示,所以我想知道是否有其他可能導致此問題。幫助,將不勝感激。如何使用Google Maps SDK for Swift找到用戶的位置?
import UIKit
import GoogleMaps
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.accessibilityElementsHidden = false
mapView.myLocationEnabled = true
self.view = mapView
if let mylocation = mapView.myLocation {
print("User's location: \(mylocation)")
} else {
print("User's location is unknown")
}
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
簡短的回答 - 你不能直接。 http://stackoverflow.com/questions/20967496/google-maps-ios-sdk-getting-current-location-of-user您需要直接查詢位置管理器。 –
謝謝你這個作品 –