Search code examples
iosgoogle-mapsgoogle-maps-api-3google-maps-sdk-ios

How to display a Google Maps info window on the right side in iOS


I would like to display a custom infoWindow to the right of the marker that has been tapped.

Per default, the info window is displayed at the top of the info window with

let anchorPoint = CGPointMake(0.5, 0.0).

In order to display my info window at the right side, I have to anchor it to the right bottom of my marker. So I changed the info window anchor point like this:

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       
}

But since the info window's bottom is centered around the marker's anchor point, I have to increase the info markers x position by 0.5 * infoMarker.width and readjust the camera if neccessary. I have no clue how to do this.

Basically I'm looking for the iOS way of adding an offset to the info window (comparable to pixelOffset in the JS API).


Solution

  • Setting up infoWindowanchor at any point can work for example while creating marker(if infowindow is of same size for all) Following worked for me:

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