【发布时间】:2015-11-15 00:24:56
【问题描述】:
我试图在GMSMapView 中显示myLocation。这是我到目前为止的代码:
class ViewController: UIViewController {
// MARK: Properties
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()
let stdZoom: Float = 12
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.requestWhenInUseAuthorization()
mapView.myLocationEnabled = true
if let myLocation = mapView.myLocation {
print("my location enabled");
let update = GMSCameraUpdate.setTarget(myLocation.coordinate, zoom: stdZoom)
mapView.moveCamera(update)
} else {
print("my location could not be enabled")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我按照问题here 的建议将CLLocationManager 设置为类变量,并在Xcode 的Info.plist 文件中将NSLocationWhenInUseUsageDescription 设置为字符串,但是从来没有提示允许定位服务显示在模拟器中,我得到以下控制台输出:
2015-11-14 19:17:14.752 ios-demo[34759:569776] Simulator user has requested new graphics quality: 100
my location could not be enabled
2015-11-14 19:17:15.838 ios-demo[34759:569776] Google Maps SDK for iOS version: 1.10.21020.0
有人能指出我缺少什么吗?
【问题讨论】:
标签: ios swift google-maps xcode7 cllocationmanager