Google maps SDK for iOS: move marker and info window to show fully
With Google maps SDK for iOS you can use google maps in your iOS app [don't forget to obtain the api key, follow the Google maps SDK for iOS documentation].
A good feature is that you can create a custom info window for a marker, implementing the GMSMapViewDelegate.
So the content of YourViewController.h will start with:
#import <UIKit/UIKit.h> #import <GoogleMaps/GoogleMaps.h> @interface YourViewController : UIViewController <GMSMapViewDelegate>
Well, in the YourViewController.m file you can create your custom info window (max 500x500) for markers [marker.userData is the property where you can store custom data to use], implementing the method:
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker; {...}
Ok, now you have markers with custom info window but if the info window is so big, it will appear incorrectly under or out the mapview bounds. So you wanna move the marker and the info window into the mapview frame so you can show them fully.
You can do this using the delegate's method:
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
Pay attention, if you will return NO the map will use the default behavior. So you must return YES and use the selectedMarker property to show the info window at the custom position.
Below the implementation of a custom/infowindow moved of 100 points:
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker { CGPoint point = [mapView.projection pointForCoordinate:marker.position]; point.y = point.y - 100; GMSCameraUpdate *camera = [GMSCameraUpdate setTarget:[mapView.projection coordinateForPoint:point]]; [mapView animateWithCameraUpdate:camera]; mapView.selectedMarker = marker; return YES; }
That's all!











