iOS google maps sdk GMSMarker positioning

喜夏-厌秋 提交于 2019-11-28 13:19:54

Have a look at using GMSProjection. To shift the center of the map 100px from the markers location you would do something like:

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
  CGPoint point = [mapView_.projection pointForCoordinate:marker.position];
  point.x = point.x + 100;
  GMSCameraUpdate *camera =
      [GMSCameraUpdate setTarget:[mapView_.projection coordinateForPoint:point]];
  [mapView_ animateWithCameraUpdate:camera];
  return YES;
}

Swift 4, 3

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    var point:CGPoint = mapView.projection.point(for: marker.position)
    point.x = point.x + 100

    let camera:GMSCameraUpdate = GMSCameraUpdate.setTarget(mapView.projection.coordinate(for: point))
    mapView.animate(with: camera)

    return true
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!