Currently when I set the button to appear using the GMSMapView api, it appears on the bottom right corner.
There is another question on SO about this but this is for swift as opposed to objective-c (and it's for a different location on the screen.)
Currently when I set the button to appear using the GMSMapView api, it appears on the bottom right corner.
There is another question on SO about this but this is for swift as opposed to objective-c (and it's for a different location on the screen.)
Just adapt the solution in this post
From the top of my head it would look something like this:
let myLocationButton = mapView.subviews.last! as! UIButton
myLocationButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin
let frame = myLocationButton.frame
frame.origin.y = 10
myLocationButton.frame = frame
Create your own myLocationButton and just update your camera target to current position when tap.
Here Is a full implementation. Tried and tested:
class MyViewController : UIViewController {
var userTracker : MKUserTrackingButton? //strong reference
var compass : MKCompassButton? //strong reference
override func viewLayoutMarginsDidChange() { //when device is rotated
setUpUserLocationButton()
}
func setUpUserLocationButton() {
let buttonMargins : CGFloat = 12
if userTracker == nil {
userTracker = MKUserTrackingButton(mapView: self.mapView)
userTracker!.backgroundColor = .white
view.addSubview(userTracker!)
userTracker!.autoresizingMask = [.flexibleTopMargin, .flexibleLeftMargin]
setGenericShadow(subView: userTracker!)
self.mapView.showsCompass = false
compass = MKCompassButton(mapView: mapView)
compass!.compassVisibility = .visible
compass!.autoresizingMask = [.flexibleTopMargin, .flexibleLeftMargin]
view.addSubview(compass!)
}
compass!.frame.origin.x = (self.view.frame.width) - (compass!.frame.size.width) - (self.view.safeAreaInsets.right == 0 ? buttonMargins : self.view.safeAreaInsets.right )
compass!.frame.origin.y = self.view.safeAreaInsets.top + buttonMargins
userTracker!.frame.origin.x = (self.view.frame.width) - (userTracker!.frame.size.width) - (self.view.safeAreaInsets.right == 0 ? buttonMargins : self.view.safeAreaInsets.right )
userTracker!.frame.origin.y = self.view.safeAreaInsets.top + buttonMargins + compass!.frame.height + buttonMargins
}
func setGenericShadow(subView:UIView) {
subView.layer.shadowPath = UIBezierPath(rect: subView.bounds).cgPath
subView.layer.shadowOpacity = 0.2
subView.layer.shadowColor = UIColor.black.cgColor
subView.layer.shadowOffset = CGSize(width: 0, height: 0)
subView.layer.shadowRadius = 4
subView.layer.cornerRadius = 5
subView.layer.masksToBounds = false
}
}