【发布时间】:2014-12-20 09:13:07
【问题描述】:
我想使用 Google Maps SDK 在 iOS 应用上显示我的位置。但是,它无法获取我的位置。我参考了以下文件,document1,document2
这是我的代码。它只显示英国的地图。
请帮我解决问题。
import UIKit
class SearchVC: UIViewController,CLLocationManagerDelegate{
///Google Map
@IBOutlet weak var mapView:GMSMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager:CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus){
if status == .AuthorizedWhenInUse{
locationManager.startUpdatingLocation()
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
}
func locationManager(manager:CLLocationManager!, didUpdateLocations locations:[AnyObject]!){
if let location = locations.first as? CLLocation{
mapView.camera = GMSCameraPosition(target:location.coordinate, zoom:15,bearing:0, viewingAngle:0)
locationManager.stopUpdatingLocation()
}
}
}
【问题讨论】:
-
您是否修改了 info.plist 文件?
-
是的。我将键添加为“NSLocationWhenInUseUsageDescription”,将值添加为“通过访问您的位置,此应用可以找到好餐馆”。
-
didUpdateLocations 是否返回位置?还是它只是默默地失败?你有模拟位置吗?
-
didUpdateLocations 返回一个位置,但它的位置是英国,可能纬度=0.0,经度=0.0。
标签: ios swift google-maps-sdk-ios