ios - 停止更新地图查看位置
问题描述
加载后如何停止更新用户的位置。就像阻止用户位置引脚继续移动和更新一样。我仍然想要那里的位置图标,但要停止更新。已经试过了
locationmanager.delegate = nil
locationManager.stopMonitoringSignificantLocationChanges()
解决方案
import UIKit
import GoogleMaps
class Map: UIViewController, CLLocationManagerDelegate
{
var mapView: GMSMapView?
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.mapView = GMSMapView.map(withFrame: CGRect.zero, camera: GMSCameraPosition.camera(withLatitude: 40.7, longitude: -74.0, zoom: 4.0))
view = mapView
if (CLLocationManager.locationServicesEnabled()){
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let center = CLLocationCoordinate2D(latitude: locations.last!.coordinate.latitude, longitude: locations.last!.coordinate.longitude)
let camera = GMSCameraPosition.camera(withLatitude: center.latitude, longitude: center.longitude, zoom: 4.0);
self.mapView?.camera = camera
self.mapView?.isMyLocationEnabled = true
let marker = GMSMarker(position: center)
print("Latitude :\(center.latitude)")
print("Longitude :\(center.longitude)")
marker.title = "Current Location"
locationManager.stopUpdatingLocation()
}
}
在这种情况下,如果您想在您的位置之后停止更新位置,那么您需要编写:-
locationManager.stopUpdatingLocation()
推荐阅读
- node.js - CORS 使用“授权”标头和数据阻止 axios 请求
- javascript - 按下按钮更改图像
- android - 将空的 EditText 转换为整数 Android Studio
- python - Group-by 然后在每组中进行行移位
- java - Camera2 在触摸焦点上。将 TextureView onClick 映射到 sensorArraySize
- android-studio - android studio github 没有更新项目
- tableau-api - 如何计算 Tableau 中 2 个不同工作表之间总计的百分比?
- javascript - 在 javascript 中为 cookie 过期设置午夜
- jasper-reports - 带有 net.sf.jasperreports.export.pdf.field.read.only" value="false" 的 textField 详细信息带未在 Acrobat Reader DC 中呈现
- javascript - 如何在加载 fetch 之前显示加载消息