swift - 如何在再次打开应用程序之前从之前的会话中删除 google 地图标记?
swift - how to delete google maps markers from previous session before app is opened again?
我想要完成的事情:
open app to see a clear google map view
place a marker on map
if the app is navigated away from(i.e. pressing the home button or double pressing home button to go to different app)
clear all markers on map
目前正在存储和保存标记,直到我再次打开该应用程序,但如果从该应用程序导航离开,我希望清除它们。
override func viewDidLoad() {
super.viewDidLoad()
//thought this could possibly clear any previous markers before app fully runs again
self.googleMapView.clear()
self.locationManager.requestAlwaysAuthorization()
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startMonitoringSignificantLocationChanges()
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.googleMapView = GMSMapView(frame: self.mapViewContainer.frame)
self.view.addSubview(self.googleMapView)
}
基于此 documentation,您可以通过将 GMSMarker
的 map
属性 设置为 nil
从地图中删除标记。
在方法的开头添加这个条件:
func setuplocationMarker(coordinate: CLLocationCoordinate2D) {
if locationMarker != nil {
locationMarker.map = nil
}
...
}
作为参考,你可以试试这个Swift tutorial。
我想要完成的事情:
open app to see a clear google map view
place a marker on map
if the app is navigated away from(i.e. pressing the home button or double pressing home button to go to different app)
clear all markers on map
目前正在存储和保存标记,直到我再次打开该应用程序,但如果从该应用程序导航离开,我希望清除它们。
override func viewDidLoad() {
super.viewDidLoad()
//thought this could possibly clear any previous markers before app fully runs again
self.googleMapView.clear()
self.locationManager.requestAlwaysAuthorization()
self.locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startMonitoringSignificantLocationChanges()
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.googleMapView = GMSMapView(frame: self.mapViewContainer.frame)
self.view.addSubview(self.googleMapView)
}
基于此 documentation,您可以通过将 GMSMarker
的 map
属性 设置为 nil
从地图中删除标记。
在方法的开头添加这个条件:
func setuplocationMarker(coordinate: CLLocationCoordinate2D) {
if locationMarker != nil {
locationMarker.map = nil
}
...
}
作为参考,你可以试试这个Swift tutorial。