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
How to Use Afnetworking or Sthttprequest to Make a Request of a Soap Web Service
Instagram API Prevents Redirection to iOS App Upon Successful Login with 400 Bad Request Error
Universal Link Broken in iOS 11.2
Xcode 5/iOS 7 - Localization Not Working in Simulator
Detect When a Unicode Character Cannot Be Displayed Correctly
Why Isn't Preferredcontentsize Used by iPhone 6 Plus Landscape
Nsdateformatter Datefromstring Always Returns Nil
iOS Custom Annotation: a View Below the Annotation Pin
Is Char Signed or Unsigned by Default on iOS
"Invalid Predicate: Nil Rhs" for Second Argument in Nspredicate Format
Ios: Usage of Self and Underscore(_) with Variable
Why Is Uiwebview Cangoback=No in iOS7
Checking Push Notification Registration: Isregisteredforremotenotifications Not Updating
Navigationcontroller.Navigationitem VS Navigationitem
Visually Modifying a Uitoolbar from Xcode Storyboard
Where Does a Swift iOS Application Begin Its Life