2016-10-30 27 views
0

我跟踪了一些在线文档here来设置Google地图API,我可以将其加载到视图中。我确实有一个问题 - 当我得到用户的位置时,Google地图的视图不会显示/捕捉/动画到用户的位置。我能够成功获取用户的位置。无法将googlemaps设置为用户活动位置swift

我的位置经理:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ 
    let newUserLocation: CLLocation = locations[0] 
    let latitude: CLLocationDegrees = newUserLocation.coordinate.latitude 
    let longitude: CLLocationDegrees = newUserLocation.coordinate.longitude 
    userLocation = PFGeoPoint(latitude:latitude, longitude:longitude) 


    let Camera = GMSCameraPosition.camera(withLatitude: userLocation.latitude, longitude: userLocation.longitude, zoom: 15) 
    self.MapView.isMyLocationEnabled = true 
    self.MapView = GMSMapView.map(withFrame: CGRect.zero , camera: Camera) 

} 

我viewDidLoad中:

override func viewDidLoad() { 
    super.viewDidLoad() 

    locationManager.delegate = self 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest 
    locationManager.requestAlwaysAuthorization() 
    locationManager.startUpdatingLocation() 


} 

回答

0

我发现了一个解决办法,不知道这是否是有效的,但是,它在我的iPhone模拟器为我工作。我在创建Camera变量后最终添加了这两行代码:

MapView.animate(toLocation: newUserLocation.coordinate) 
    MapView.animate(toZoom: 15)