Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to Fix a Google Maps Marker to the Center of its Map always in iOS using swift?

What i want is I want to fix the marker position to the centre of my map view. when map moves still my marker should stick to that centre point. Code for marker is shown below:

var pin:GMSMarker = GMSMarker(position: CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude))
pin.icon = UIImage(named: "img_map_pin")
pin.map = mapView?
pin.infoWindowAnchor = CGPointMake(0.44, 0.44)
mapView?.selectedMarker = pin

I want to make same as Uber has done. When map moves marker is in centre and after map stops moving I get that point's address from map.

like image 443
Pooja Shah Avatar asked Jan 19 '26 14:01

Pooja Shah


1 Answers

Assign GMSMapViewDelegate to class and add below code

 func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
     pin.position = position.target
 }
like image 191
steveSarsawa Avatar answered Jan 22 '26 12:01

steveSarsawa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!