使用 swift 4.1 在 google 地图上自定义 Window 信息

Custom Window info on google map using swift 4.1

我正在为 ios swift 4.1 中 google 地图上的自定义 window 信息编写此方法,但 window 不显示在 google地图

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

 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()
}