Я пытаюсь реализовать гео-фехтование с помощью GoogleMaps в iOS.Я инициализировал объект CLLocationManager с необходимыми свойствами, а также предоставил регион для начала мониторинга, используя следующий код.
private func setupGoogleMapServicecs() {
let camera = GMSCameraPosition.camera(withLatitude: CLLocationDegrees(latitude), longitude: CLLocationDegrees(longitude), zoom: 6.0)
let mapRect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
mapView = GMSMapView.map(withFrame: mapRect, camera: camera)
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
mapView.delegate = self
self.view.addSubview(mapView)
let circleCenter = CLLocationCoordinate2D(latitude: CLLocationDegrees(latitude), longitude: CLLocationDegrees(longitude))
//-33.86 & 151.20
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = circleCenter
marker.title = "Title"
marker.snippet = "Snippet"
marker.icon = UIImage(named: "ico-pin-map")
marker.map = mapView
let circ = GMSCircle(position: circleCenter, radius: CLLocationDistance(circularRadius))
circ.fillColor = UIColor(red: 0.35, green: 0, blue: 0, alpha: 0.05)
circ.strokeColor = .red
circ.strokeWidth = 5
circ.map = mapView
self.registerLocationManager()
}
private func registerLocationManager() {
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = 50
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startUpdatingLocation()
let centrePosition = CLLocationCoordinate2D(latitude: CLLocationDegrees(latitude), longitude: CLLocationDegrees(longitude))
region = CLCircularRegion(center: centrePosition, radius: CLLocationDistance(circularRadius), identifier: "test")
region.notifyOnEntry = true
region.notifyOnExit = true
self.locationManager.startMonitoring(for: region)
}
Более того, я настроил ключи в info.plist следующим образом ![enter image description here](https://i.stack.imgur.com/H2Ql1.png)
Кроме того, я реализовал следующие методы делегата, чтобы проверить, какой из нихможет вызываться при входе / выходе из указанного региона.
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
print("test")
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
//Testing Code
let alert = iAlert()
alert.showSingleOptionOkAlertWith(Title: "Geofencing", message: "didRangeBeacons", presenter: self)
}
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion) {
print("The monitored regions are: \(manager.monitoredRegions)")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
//Testing Code
let alert = iAlert()
alert.showSingleOptionOkAlertWith(Title: "Geofencing", message: "didExitRegion", presenter: self)
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
//Testing Code
let alert = iAlert()
alert.showSingleOptionOkAlertWith(Title: "Geofencing", message: "didEnterRegion", presenter: self)
}
Только один раз этот метод называется didEnterRegion, когда я простоял 5 минут в указанном регионе, но после этого он больше не вызывается.Пожалуйста, предложите, если я пропустил какой-либо шаг или что-то еще, что я могу попробовать?Я хочу интегрировать его в GoogleMap , я попробовал MKMapKit , и он работает.