shilparamesh shilparamesh - 1 year ago 369
Swift Question

how to move the maker along with moving of google map in ios?

I am displaying marker in some particular place...along with displaying the current address in label on google i want to change the location by moving the google map...but the problem is when am moving the map simultaneously i should move the marker along with the map..and i should display the address of that location in address label..can anyone help to achieve this...
I tried like this:
let destinationMarker = GMSMarker(position: self.destinationLocation.coordinate)

let image = UIImage(named:"sourcemarker")
destinationMarker.icon = image
destinationMarker.draggable = true = self.viewMap
//viewMap.selectedMarker = destinationMarker
destinationMarker.title = "hi"
destinationMarker.userData = "changedestination" func mapView(mapView: GMSMapView, didEndDraggingMarker marker: GMSMarker) {
if marker.userData as! String == "changedestination"
self.destinationLocation = CLLocation(latitude: marker.position.latitude, longitude: marker.position.longitude)
self.destinationCoordinate = self.destinationLocation.coordinate


thanks in advance...

Answer Source

There is one trick that can help you out here. Instead of using a GMSMarker here, put an image pointing to the center, over your Google MapView.

You can easily find the coordinates of Map's center using this :

double latitude =;
double longitude =;

Or this

GMSCoordinateBounds *bounds = nil;
bounds = [[GMSCoordinateBounds alloc] initWithRegion: visibleRegion];

CLLocationCoordinate2D centre = CLLocationCoordinate2DMake(
                                                           (bounds.southWest.latitude + bounds.northEast.latitude) / 2,
                                                           (bounds.southWest.longitude + bounds.northEast.longitude) / 2);

Now you can get the location address by using Geocoding API by google.

Here is the reference :

You can refresh Address when this delegate method is called :

- (void) mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position 

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download