【发布时间】:2021-01-12 00:09:45
【问题描述】:
我正在尝试在 xcode 中测试 Google Maps SDK 的基本功能。我在 Xcode 模拟器中运行了下面的代码,它运行得很好。但是,当我尝试在 iPhone 8 上运行它时,它会正确显示我的位置,但地图视图会不断重新加载,最终,我的手机内存已满,应用程序崩溃。我是使用 Google Maps SDK 的新手,尽管我怀疑这是某种内存泄漏。任何建议或帮助将不胜感激。
import CoreLocation
import GoogleMaps
import UIKit
class ViewController: UIViewController, CLLocationManagerDelegate {
let manager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
GMSServices.provideAPIKey("")
// Do any additional setup after loading the view, typically from a nib.
print("View has loaded")
// Do any additional setup after loading the view.
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
print("License: \n\n\(GMSServices.openSourceLicenseInfo())")
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.first else {
return
}
let coordinate = location.coordinate
let camera = GMSCameraPosition.camera(withLatitude: coordinate.latitude, longitude: coordinate.longitude, zoom: 12.5)
let mapView = GMSMapView.map(withFrame: view.frame, camera: camera)
view.addSubview(mapView)
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = coordinate
marker.title = "My Location"
marker.snippet = "On Earth"
marker.map = mapView
}
}
..
【问题讨论】:
标签: xcode memory memory-leaks crash maps