I'm using google place API to get proper information of current place. I used this code in the App and get success to fetch list of all nearby locations, but how can I recognize my exact current location from the list?
I read doc and find that we get current location from the list based on likelihoods (value between 0 to 1).
A higher value of likelihoods means a greater probability that the place is the best match.
But my current location is coming into this list but likelihoods value is not higher.
So I have two questions:
1) How can I recognize my exact current location? Any other setting is there or any alert-net way is there? (Without use of place picker)
2) If I leave current place then I want to perform some action so How can I get that I left this place recently? like checked-In/Out?
Google's API requires that you initialize a CLLocationManager. Since you already have a location manager, you can set your class to be a CLLocationManagerDelegate. This provides you with native iOS methods that mean you can get both an exact location and a notification that the location has changed
To get an exact location:
[self.locationManager requestLocation]; //Get the current location once (iOS 9 and above)
To monitor location:
[self.locationManager startUpdatingLocation] // Ask for the current location until you call stopUpdatingLocation
// or
[self.locationManager startMonitoringSignificantLocationChanges] // Tells you when your location has greatly changed
You then need to conform to the protocol, which has 2 methods at minimum:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations
// Do anything that you need to do once you have a location update
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
// Your location update failed, handle it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With