How to change location of my location button in google maps using swift

一世执手 提交于 2019-12-20 17:38:04

问题


I am using google maps in my project i want to show my location button a bit up how should i do that using swift


回答1:


You can change the position of the MapControls by set the padding for your map view .

 let mapView = GMSMapView()

 mapView.isMyLocationEnabled = true
 mapView.settings.myLocationButton = true

 mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 50)

It will change the padding of the my location control. From bottom 50px and from right 50px

Refer the below screenshot which added the padding of 50px from bottom and right.




回答2:


Like Subramanian, this works very well :

mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)

This is perfect if you have a navigation bar in your app.




回答3:


Update for swift 4 : just change the position of my location button only

for object in self.mapView.subviews{
            if(object.theClassName == "GMSUISettingsPaddingView"){
                for view in object.subviews{
                    if(view.theClassName == "GMSUISettingsView"){
                        for btn in view.subviews{
                            if(btn.theClassName == "GMSx_QTMButton"){
                                var frame = btn.frame
                                frame.origin.y = frame.origin.y - 100
                                btn.frame = frame

                            }
                        }
                    }
                }
            }
        }

    public extension NSObject {
    public var theClassName: String {
        return NSStringFromClass(type(of: self))
    }
}


来源:https://stackoverflow.com/questions/44777652/how-to-change-location-of-my-location-button-in-google-maps-using-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!