使用 swift 4.1 在谷歌地图上自定义窗口信息



我在iOS Swift 4.1中为谷歌地图上的自定义窗口信息编写此方法,但窗口没有显示在谷歌地图上

我也设置了代表,但没有结果

func mapView(_mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView?{
let infoWindow: InfoWindow = Bundle.main.loadNibNamed("InfoWindow", owner: self.view, options: nil)!.first! as! InfoWindow
infoWindow.numberCarLabel.text = "TLA-618"
infoWindow.dateLabel.text = "2018-05-02 10:39:43"
infoWindow.digreeLabel.text = "94"
infoWindow.addressLabel.text = "Sunrise Appartments, Marine Promenade, Karachi"
infoWindow.kilometterLabel.text = "0"
return infoWindow
}

好的 查看代码后,首先委托函数名称中有拼写错误

正确的是:

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let infoWindow: InfoWindow = Bundle.main.loadNibNamed("InfoWindow", owner: self.view, options: nil)!.first! as! InfoWindow
infoWindow.numberCarLabel.text = "TLA-618"
infoWindow.dateLabel.text = "2018-05-02 10:39:43"
infoWindow.digreeLabel.text = "94"
infoWindow.addressLabel.text = "Sunrise Appartments, Marine Promenade, Karachi"
infoWindow.kilometterLabel.text = "0"
return infoWindow
}

您在这里还有一个问题,func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])您不需要每次CLLocationManager报告位置时都重新分配地图视图

用这个替换你的func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])实现

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation = locations.last
let camera = GMSCameraPosition.camera(withLatitude: userLocation!.coordinate.latitude,
longitude: userLocation!.coordinate.longitude, zoom: 13.0)
mapView.isMyLocationEnabled = true
self.mapView.animate(to: camera)
locationManager.stopUpdatingLocation()
}

最新更新