Search code examples
iosswiftgoogle-maps-sdk-ios

Google maps draws circle at wrong position


I'm showing marker and drawing circle using the same coordinates. Don't know why but my marker is offset a little bit to the top. How do you think what is the problem?

enter image description here

override func viewDidLoad() {
    super.viewDidLoad()

    let camera = GMSCameraPosition.camera(withLatitude: 37.36, longitude: -122.0, zoom: 13.0)

    setupMapWith(cameraPosition: camera)
    showMarker(position: camera.target)
    circleWith(position: camera.target)
}

func showMarker(position: CLLocationCoordinate2D) {
    let marker = GMSMarker()
    marker.position = position
    marker.title = "Palo Alto"
    marker.snippet = "San Francisco"
    let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
    markerView.backgroundColor = .red
    marker.iconView = markerView
    marker.map = mapView
}

func circleWith(position: CLLocationCoordinate2D) {

    let circ = GMSCircle(position: position, radius: 1000)
    circ.fillColor = UIColor.MapAreaFilter.areaFilterColor
    circ.map = mapView
}

Solution

  • Try setting your marker's groundAnchor property:

    marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)