Ground overlays are overlays on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the map.
A ground overlay is an image that is fixed to a map. Unlike markers, ground overlays are oriented against the Earth's surface rather than the screen, so rotating, tilting or zooming the map will change the orientation of the image.
To add a ground overlay, create a
GMSGroundOverlay object that defines both
an icon and a bounds. Failing to specify either will cause the ground overlay
to not appear on the map. You can optionally specify additional settings that
will affect the positioning of the image on the map. Once you've defined the
necessary options, set this object's
map property to add the overlay.
Add an overlay
- Instantiate a new
- Set the
iconproperty to an instance of
- Set the
boundsproperty to an instance of
GMSCoordinateBounds. The bounds represent the south west, and north east corners of the image.
- Set optional properties, such as
zoomLevel, as desired.
- Set the
mapproperty - the image appears on the map.
The below example demonstrates how to add a ground overlay to an existing
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(40.712216,-74.22655); CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(40.773941,-74.12544); GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWest coordinate:northEast]; // Image from http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg UIImage *icon = [UIImage imageNamed:@"newark_nj_1922.jpg"]; GMSGroundOverlay *overlay = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds icon:icon]; overlay.bearing = 0; overlay.map = mapView_;
Remove an overlay
You can remove a ground overlay from the map by setting your
map property to
nil. Alternately, you can remove all
of the overlays (including ground overlays currently on the map by calling the
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.742 longitude:-74.174 zoom:6]; mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; ... [mapView_ clear];
If you wish to make modifications to a ground overlay after you've added it to
the map, ensure that you keep hold of the
GMSGroundOverlay object. You can
modify the ground overlay later by making changes to this object.
GMSGroundOverlay *overlay = [GMSGroundOverlay groundOverlayWithPosition:newark icon:icon]; overlay.map = mapView_; ... overlay.tappable = YES;