我正在尝试获取用户的当前位置,但是,地图卡在英国。我编辑了info.plist以获得许可。这是我的mapviewcontroller类,任何人都可以告诉我我做错了什么?感谢
import UIKit
import GoogleMaps
class MapViewController: UIViewController {
var newMap: Bool!
let locationManager = CLLocationManager()
var didFindMyLocation = false
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
self.locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
}
extension MapViewController: CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthroizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedAlways {
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue: CLLocationCoordinate2D = manager.location!.coordinate
let camera = GMSCameraPosition.cameraWithLatitude(locValue.latitude,
longitude: locValue.longitude, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.camera = GMSCameraPosition(target: locValue, zoom: 15, bearing: 0, viewingAngle: 0)
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
locationManager.stopUpdatingLocation()
}
}
编辑:我正在模拟器上测试它,并将模拟位置设置为伦敦以外的城市。
答案 0 :(得分:0)
我的代码没有错。这是因为我忘了启用Google Place API!