import UIKit
import GoogleMaps
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate{
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
// Do any additional setup after loading the view, typically from a nib.
}
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: [CLLocation]) {
if let location = locations.first {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
}
这是我写的代码,但我无法获取用户的位置。 我在info.plist
中加入了NSLocationWhenInUseUsageDescriptation
。 有人可以帮助我吗?我从很长一段时间一直在尝试。如何使用google api获取用户的位置
我在这些行中收到错误。
=================================
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
==================================
有人可以帮我解决这个问题吗?类型的
1值“的MKMapView”没有成员“myLocationEnabled” 2值类型“的MKMapView”的没有成员“设置 3无法分配类型的值“GMSCameraPosition!键入 'MKMapCamera'
这是第3误差正在逐渐
我确切的错误是@IBOutlet弱VAR的MapView:的MKMapView! 是我更改这个@IBOutlet弱var mapView:GMSMapView! 我得到线程1错误@IBOutlet弱var mapView:MKMapView!在这个只有地图中查看,但不销我的位置
和我不是回答
可以请你,你收到的错误编辑你的问题? – lorenzoliveto
我记得,你不需要在info.plist中添加一些东西。 – LKM