How to Setregion with Google Maps Sdk for iOS

How to setCenter mapview with location in google maps sdk for iOS

Create a new camera with the GMSCameraPosition constructor

+ (GMSCameraPosition *)cameraWithTarget:(CLLocationCoordinate2D)target zoom:(CGFloat)zoom

then use the method

- (void)animateToCameraPosition:(GMSCameraPosition *)cameraPosition;

You can also just use

- (void)animateToLocation:(CLLocationCoordinate2D)location;

but the previous allows you to change the zoom, bearing, and viewing angle within the camera constructor if you want more control over the final appearance of the camera.

How to fit bounds for coordinate array with google maps sdk for iOS?

Here's my solution for this problem. Building a GMSCoordinateBounds object by multiple coordinates.

- (void)focusMapToShowAllMarkers {       
CLLocationCoordinate2D myLocation = ((GMSMarker *)_markers.firstObject).position;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:myLocation coordinate:myLocation];

for (GMSMarker *marker in _markers)
bounds = [bounds includingCoordinate:marker.position];

[_mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:15.0f]];
}

Updated answer: Since GMSMapView markers property is deprecated, you should save all markers in your own array.

updated swift 3 answer:

    func focusMapToShowAllMarkers() {
let firstLocation = (markers.first as GMSMarker).position
var bounds = GMSCoordinateBoundsWithCoordinate(firstLocation, coordinate: firstLocation)

for marker in markers {
bounds = bounds.includingCoordinate(marker.position)
}
let update = GMSCameraUpdate.fitBounds(bounds, withPadding: CGFloat(15))
self.mapView.animate(cameraUpdate: update)
}

How to get CGPoint of location with google maps sdk for iOS?

It's basically the opposite of this question, for example:

GMSMapView* mapView = ...;
CLLocationCoordinate2D coordinate = ...;
...
CGPoint point = [mapView.projection pointForCoordinate: coordinate];

Adding pictures to locations in Google IOS Maps SDK

Just set the icon property of GMSMarkerOptions to a UIImage.

There is an example of this here:

https://developers.google.com/maps/documentation/ios/marker#customize_a_marker

UPDATE:

You can use a UIImagePickerController to take a picture. You would need to resize the returned UIImage, to make it small enough for a marker.

You can use the myLocation property on the GMSMapView to get the current location to add the marker to. You would need to set myLocationEnabled to YES on the GMSMapView when you first create the map view, in order for myLocation to track your current location.



Related Topics



Leave a reply



Submit