【发布时间】:2018-05-10 11:19:48
【问题描述】:
我正在研究谷歌地图,我想使用UISwitch 在谷歌地图上显示位置。我可以使用谷歌地图按钮显示位置,但我不知道如何使用UISwitch。正如您在我的第一张图片中看到的那样,我能够获得位置,但我怎样才能通过使用UISwitch(我正在使用MFSideMenu)显示侧边菜单来做到这一点。有什么帮助吗?
override func viewDidLoad() {
super.viewDidLoad()
setupSwitch()
locManager = CLLocationManager()
locManager.delegate = self
locManager.requestWhenInUseAuthorization()
locManager.startMonitoringSignificantLocationChanges()
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Error while getting location\(error)")
}
}
func setupSwitch() {
locationSwitch.addTarget(self, action: #selector(switchValueDidChange(_:)), for: .valueChanged)
}
@objc func switchValueDidChange(_ sender: UISwitch) {
//Called when yourSwitch change its value
if locationSwitch.isOn {
menuContainerViewController.toggleLeftSideMenuCompletion({
//self.locManager.startUpdatingLocation()
})
} else {
//Stops the location updates.
self.locManager.stopUpdatingLocation()
}
}
private func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
_ = GMSCameraPosition.camera(withLatitude: (location?.coordinate.latitude)!, longitude: (location?.coordinate.longitude)!, zoom: 17.0)
//Finally stop updating location otherwise it will come again and again in this delegate
self.locManager.stopUpdatingLocation()
}
这是我写的代码,但它似乎不起作用
【问题讨论】:
标签: ios swift google-maps navigation swift4