我正在绘制一些空白,我想隐藏Google Maps iOS API中的蓝色位置点。但是,如果我设置
self.mapView.myLocationEnabled = false
然后停止所有位置服务。我只需要暂时禁用蓝点,是否有办法在继续更新后台位置的同时使其清晰?
答案 0 :(得分:1)
我测试了相同的内容,我将以下代码行添加到我的应用程序中,并在Google地图中显示用户位置。
mapView.myLocationEnabled=YES;
如果我完全删除了上面的代码行,它会显示所有其他注释,但不会显示用户位置
答案 1 :(得分:0)
我花了一段时间,但我想我已经开始工作了。
在viewDidLoad()中:
// MARK: Location Settings
// Location Manager
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
mapView.delegate = self
mapView.settings.myLocationButton = true
}
您需要这段代码来分配代理并开始更新位置。这也会将位置按钮添加到谷歌地图。您还必须确保将授权消息添加到info.plist。
{key=NSLocationWhenInUseUsageDescription}: {type=String}: {value=custom message}
。
然后你需要扩展这些委托(把它们放在你班级外的MapViewController的底部):
// MARK: - Extension: LocationManager
extension MapViewController: CLLocationManagerDelegate {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
}
// MARK: - Extension: GMSMapView
extension MapViewController: GMSMapViewDelegate {
func didTapMyLocationButtonForMapView(mapView: GMSMapView) -> Bool {
locationManager.updateLocation()
return false
}
}
<强> CLocationManagerDelegate: 强>
<强> GMSMapViewDelegate: 强>
答案 2 :(得分:0)
在初始化mapView后立即执行此操作
mapView.settings.myLocationButton = false
答案 3 :(得分:-1)
配置相机位置
let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 48.857165, longitude: 2.354613, zoom: 8.0)
viewMap.camera = camera
viewMap.delegate = self
初始化半径为0的圆
let circle = GMSCircle.init(position: camera.target, radius: 0)
circle.fillColor = UIColor.clear
circle.map = viewMap