ios - 如何在 iOS 的右侧显示 Google map 信息窗口

标签 ios google-maps google-maps-api-3 google-maps-sdk-ios

我想在被点击的标记的右侧显示一个自定义信息窗口

默认情况下,信息窗口显示在信息窗口的顶部,带有

let anchorPoint = CGPointMake(0.5, 0.0).

为了在右侧显示我的信息窗口,我必须将它固定在我的标记的右下角。所以我像这样更改了信息窗口 anchor :

func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! { 

    //load info window from xib
    //let infoView = ...
    let infoWindowAnchor = marker.infoWindowAnchor
    let newAnchor = CGPointMake(1.0, 1.0)
    marker.infoWindowAnchor = newAnchor
    //...

    return infoView       
}

但由于信息窗口的底部以标记的 anchor 为中心,我必须将信息标记的 x 位置增加 0.5 * infoMarker.width 并在必要时重新调整相机。我不知道该怎么做。

基本上,我正在寻找向信息窗口添加偏移量的 iOS 方式(与 JS API 中的 pixelOffset 相当)。

最佳答案

在任何时候设置 infoWindowanchor 都可以工作,例如在创建标记时(如果 infowindow 的大小相同) 以下对我有用:

        let marker1 = GMSMarker()
        marker1.position = coordinatesLocationOne
        marker1.title = "US"
        marker1.snippet = "US"
        marker1.infoWindowAnchor = CGPoint(x: 2.5, y: 2.5)

关于ios - 如何在 iOS 的右侧显示 Google map 信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34991412/

相关文章:

ios - 如何在 Swift 中更新 Parse 用户信息?

iOS Storyboard : How to segue to the second view with a back button to the first view, 但不显示第一个 View

ios - 如何安全地在UITableView中使用未初始化的数组并显示一个空表

google-maps - 谷歌地图无法加载。卡在 authenticationService.authenticate

javascript - 将 Google map 置于选择选项 AngularJS 上

javascript - Google Map V3 Infowindow.open 错误

ruby-on-rails - 没有模型的 Google-maps-for-Rails

ios - Apple 是如何在 Apple Music 中制作专辑封面背后的模糊效果的?

javascript - 不以 map 标记为中心

javascript - Google map API - 使用 Infowindow 控制位置