ios - 使用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()
}
推荐阅读
- unit-testing - bloc handleError 不会在 dart 中捕获错误
- javascript - 如何从 url 中删除或隐藏 /#file_name
- html - SyntaxError:我的简单节点应用程序中 JSON 输入意外结束..无法获取数据
- python - 我在 BattleShips 游戏 python 中找不到无限循环
- json - 如何使用 luvit 读取 url 的 json
- android-studio - 删除应用程序后无法在我的手机上构建 Android Studio 项目
- c - 从 C 调用 Fortran 函数时出现“检测到堆栈粉碎”错误
- c# - userManager.AddToRoleAsync() - 抛出异常:System.Private.CoreLib.dll 中的“Npgsql.PostgresException”
- firebase - 在没有 AppDelegate 和 SceneDelegate 的新 SwiftUI 应用程序生命周期中,我的 iOS 应用程序在哪里配置 Firebase?
- flutter - 旋转动画在开始时旋转两次