我正在为我的项目使用Google地图。我需要在InfoWindow中显示带有标题的图像。为此,我创建了新的XIB。现在,除了InfoWindow的y位置,其他所有东西都可以正常工作。我无法正确设置InfoWindow的Y轴。请帮我解决这个问题。
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
var markerData : NSDictionary?
if let data = marker.userData! as? NSDictionary {
markerData = data
}
locationMarker = marker
infoWindow.removeFromSuperview()
infoWindow = loadNiB()
guard let location = locationMarker?.position else {
print("locationMarker is nil")
return false
}
infoWindow.spotData = markerData
infoWindow.alpha = 0.9
infoWindow.layer.cornerRadius = 12
let name = markerData!["name"]!
let imageUrl = markerData!["img"]!
infoWindow.name.text = "\(name)"
let trimmedUrl = (imageUrl as AnyObject).trimmingCharacters(in: CharacterSet(charactersIn: "")).replacingOccurrences(of: " ", with: "%20")
var activityLoader = UIActivityIndicatorView()
activityLoader = UIActivityIndicatorView(style: .gray)
activityLoader.center = infoWindow.imgMarker.center
activityLoader.startAnimating()
infoWindow.imgMarker.addSubview(activityLoader)
infoWindow.imgMarker.sd_setImage(with: URL(string: trimmedUrl), completed: { (image, error, imageCacheType, imageUrl) in
if image != nil
{
activityLoader.stopAnimating()
}
else
{
print("image not found")
activityLoader.stopAnimating()
}
})
// Offset the info window to be directly above the tapped marker
infoWindow.center = mapView.projection.point(for: location)
infoWindow.center.y = infoWindow.center.y - 82
self.view.addSubview(infoWindow)
return false
}
答案 0 :(得分:0)
添加自定义标记时,请设置以下属性:
marker.infoWindowAnchor = CGPoint(x: 0.5, y: 0.8)
根据您的要求更改y
的值。
从屏幕截图中可以看出,您似乎需要增加y
值,如下所示:
infoWindow.center.y = infoWindow.center.y - 52
点击此链接以供参考:
https://developers.google.com/maps/documentation/ios-sdk/marker
希望这会有所帮助。