A Location Manager for easily implementing location services & geofencing in iOS. Ready for iOS 11.

Overview

BBLocationManager
A Location Manager for easily implementing location services & geofencing in iOS, written in Objective-C. Ready for iOS 11.

Features

  • Get current/continious/frequent location and get current geocode/address with simple API call.
  • Add or remove Geofence at current/given location. Get callback via delegate when user enter/exit a geofence, supports foreground/background, even when app is not running.
  • Read location permission status and if not provided ask for location permisssion automatically.
  • High performance, easy to use, battery friendly, use via block or delegate. Stops automatically when location update is not required.
  • Example App included for demonstrating all the features. Supports iOS 6.0 and later.

Current location and GeoCode

Getting Started

Location services is a powerful feature of iOS, but sometimes its not easy to understand all the API's and learn how to use them. With BBLocationManager, you can start using iOS Location Services API in no time. It provides good code documentation for better understanding of the methods and delegates. If you are making a location aware app or building a geofencing app like the Alarm app in iOS which reminds you to buy milk when you are near home, BBLocationManager can be your choice.

Installation

BBLocationManager can be installed through Cocoapods or manually. You can check out the example project by downloading the full source code

Supports iOS 6.0 and later.

Installing with CocoaPods

CocoaPods is very popular dependency manager for iOS projects. It automates and simplifies the process of using 3rd-party libraries like BBLocation in your projects. If you don't have cocoapods installed in your mac already, you can install it with the following command:

$ gem install cocoapods

Podfile

If you already have a Podfile, add the following line in your podfile:

pod 'BBLocationManager'

If you already dont have a podfile, To integrate BBLocationManager into your Xcode project using CocoaPods, create and add it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'

target 'YourTargetName' do
pod 'BBLocationManager'
end

Then, run the following command:

$ pod install

And the pod should be installed in your project. PLEASE NOTE: Close the yourProject.xcodeProj and open the yourProject.xcworkspace, as the pod has been initiated, from now one use the yourProject.xcworkspace to work with. Please refer to CocoaPods for detailed info.

Manual Installation

Just add the BBLocationManager.h and BBLocationManager.m files in your project From Here. Import the BBLocationManager.h file in your class where you need location support.

Permission

BBLocationManager automatically reads the current location permission status of the app and requests for permission if needed. But you need to provide some information in your info.plist file of your project depending on the minimum iOS version you are trageting. For iOS Version earlier then 8.0, a description of your purpose is recommended to provide by setting a string for the key NSLocationUsageDescription in your app's Info.plist file.

For iOS 11 and later

For iOS 11 provide a description for how your app uses location services by setting a string for the key NSLocationWhenInUseUsageDescription or NSLocationAlwaysAndWhenInUseUsageDescription in your app's Info.plist file. When you build your app using the iOS 11 SDK, you are now required to provide an NSLocationWhenInUseUsageDescription key in all cases (if you use location at all). For “Always” access, you can additionally provide a second key, which is now called NSLocationAlwaysAndWhenInUseUsageDescription. If you only provide NSLocationAlwaysAndWhenInUseUsageDescription but not NSLocationWhenInUseUsageDescription, asking for “Always” access will not work. The old iOS 8/9/10 key NSLocationAlwaysUsageDescription is now only needed for backwards compatibility, if you’re still making the app available to iOS 10 or earlier users. It’s not needed or used on iOS 11 devices.

BBLocationManager automatically reads which level of permissions to request based on which description key you provide. You should only request the minimum permission level that your app requires, therefore it is recommended that you use the "When In Use" level unless you require more access. If you want to get loation update in background (even when app not running), you MUST provide a key called UIBackgroundModes and add a item called location inside it. Please see the attached image for these keys for iOS 11 with compatibility:

Setting the keys in info.plist

For iOS 8 and later

Starting with iOS 8, you MUST provide a description for how your app uses location services by setting a string for the key NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in your app's Info.plist file. BBLocationManager automatically reads which level of permissions to request based on which description key you provide. You should only request the minimum permission level that your app requires, therefore it is recommended that you use the "When In Use" level unless you require more access. If you provide values for both description keys, the more permissive "Always" level is requested. Also, if you want to get loation update in background (even when app not running), you MUST provide a key called UIBackgroundModes and add a item called location inside it. Please see the attached image for these keys for iOS 8/9/10:

Setting the keys in info.plist

Usage

First import BBLocationManager.h header in your class. Calling [BBLocationManager sharedManager] creates an singleton class of BBLocationManager and manages everything from here. You can either use BBLocationManagerDelegate to get location/geofence related callbacks, or use Objective-C blocks to get location. For useing Geofence, the BBFenceInfo is a easy to use object, using which BBLocationManager delivers fence related data to your class. You can use lastKnownGeocodeAddress and lastKnownGeoLocation properties to get the last location/geocode the class got before.

  • To know the current location permission status call + (BOOL)locationPermission method.
  • To manually ask the user for location permission before accessing location, call -(void)getPermissionForStartUpdatingLocation method.

Getting current location (Using Block)

Get BBLocationManager's shared instance, set the desiredAcuracy and distanceFilter parameter as you like, then request for current location using block or delegate.

BBLocationManager *manager = [BBLocationManager sharedManager];
manager.desiredAcuracy = 100; //how accurate you want your location, in meters   
manager.distanceFilter = 500; //you'll be notified if user moves away 500 meters from his initial location
[manager getCurrentLocationWithCompletion:^(BOOL success, NSDictionary *latLongAltitudeDictionary, NSError *error) {
        //access the 'latLongAltitudeDictionary' dictionary using BB_LATITUDE, BB_LONGITUDE, BB_ALTITUDE key
        NSLog(@"Current Location latitude: %@", latLongAltitudeDictionary[BB_LATITUDE]);
}];

Getting current location (Using Delegate)

BBLocationManager *manager = [BBLocationManager sharedManager];
manager.desiredAcuracy = 100; //how accurate you want your location, in meters   
manager.distanceFilter = 500; //you'll be notified if user moves away 500 meters from his initial location
[manager getCurrentLocationWithDelegate:self];  
......
......
#pragma mark - BBLocationManagerDelegate methods
-(void)BBLocationManagerDidUpdateLocation:(NSDictionary *)latLongAltitudeDictionary
{
    //access the 'latLongAltitudeDictionary' dictionary using BB_LATITUDE, BB_LONGITUDE, BB_ALTITUDE key
    NSLog(@"Current Location Latitude: %@", latLongAltitudeDictionary[BB_LATITUDE]);
}

Getting current geocode/address (Using Block)

You can get user's current geocode AKA address from apple's geocode/maps server. You might need it for different purpose, and it might take a little time to get the location first and then determine the address.

BBLocationManager *manager = [BBLocationManager sharedManager];
    [manager getCurrentGeoCodeAddressWithCompletion:^(BOOL success, NSDictionary *addressDictionary, NSError *error) {
        //access the dict using BB_LATITUDE, BB_LONGITUDE, BB_ALTITUDE, BB_ADDRESS_NAME, BB_ADDRESS_STREET, BB_ADDRESS_CITY, BB_ADDRESS_STATE, BB_ADDRESS_COUNTY, BB_ADDRESS_ZIPCODE, BB_ADDRESS_COUNTY, BB_ADDRESS_DICTIONARY
        NSLog(NSString stringWithFormat:@"Current GeoCode/Address: %@", addressDictionary.description);
    }];

Add a geofence in current location

BBLocationManager *manager = [BBLocationManager sharedManager];
manager.delegate = self;
[manager addGeofenceAtCurrentLocation];
/*****can be also done using one of the following methods *****/
//[manager addGeofenceAtCurrentLocationWithRadious:100];
//[manager addGeofenceAtlatitude:59.331981f andLongitude:18.068435f withRadious:100 withIdentifier:@"MyFence-1";
//[manager addGeofenceAtCurrentLocationWithRadious:100 withIdentifier:@"MyFence-1"];
//[manager addGeofenceAtCoordinates:CLLocationCoordinate2DMake(59.331981f, 18.068435f) withRadious:100 withIdentifier:@"MyFence-1"];
//[manager addGeofenceAtCoordinates:CLLocationCoordinate2DMake(59.331981f, 18.068435f) withRadious:100 withIdentifier:nil];//If you provide identifier name 'nil', BBLocationManager will automatically asign a identifier string

Geofence and alert Geofence Alert

Get all added geofences

See which geofence is already added to get enter/exit callbacks. NOTE: You can add [maximum 20 geofences, its a limit apple put in region monitoring.

 BBLocationManager *manager = [BBLocationManager sharedManager];
    
    NSArray *geoFences = [manager getCurrentFences];
    NSString *allFencetxt = @"All fences: ";
    for (BBFenceInfo *geofence in geoFences)
    {
        NSString *txt = [NSString stringWithFormat:@"Geofence '%@' is Active at Coordinates: %@:%@ with %@ meter radious \n", geofence.fenceIDentifier, [geofence.fenceCoordinate objectForKey:BB_LATITUDE],[geofence.fenceCoordinate objectForKey:BB_LONGITUDE], [geofence.fenceCoordinate objectForKey:BB_RADIOUS]];
        NSLog(@"%@", txt);
    }

Delete a spefific geofence

 BBLocationManager *manager = [BBLocationManager sharedManager];
[manager deleteGeoFenceWithIdentifier:@"My-Geofence-3"];

Subscribe to Continious location

To get continuous location updates, use -getContiniousLocationWithDelegate: method. This will enable the BBLocationManager to listen every bit of change in location, and will keep you updated using the -BBLocationManagerDidUpdateLocation: delegate call. To stop getting continious location, call -stopGettingLocation method. Note that, until you stop the continious location, it will keep updating and will use battery life.

BBLocationManager *manager = [BBLocationManager sharedManager];
[manager getContiniousLocationWithDelegate:self];

Subscribe to Significant location change

To get significant location changes, use -getSingificantLocationChangeWithDelegate: method. This will start looking for for significant location changes, which is very power efficient. The delegate callback -BBLocationManagerDidUpdateLocation: will be called everytime BBLocationManager finds any significant location change. This can be stoped by calling the -stopGettingLocation method.

BBLocationManager *manager = [BBLocationManager sharedManager];
[manager getSingificantLocationChangeWithDelegate:self];

NOTE: Significant location change will not be called frequently. According to Apple documentation:

"Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner."

Stop getting all kind of location

BBLocationManager *manager = [BBLocationManager sharedManager];
[manager stopGettingLocation];

BBLocationManagerDelegate methods

-(void)BBLocationManagerDidUpdateLocation:(NSDictionary *)latLongAltitudeDictionary;

-(void)BBLocationManagerDidUpdateGeocodeAdress:(NSDictionary *)addressDictionary;

-(void)BBLocationManagerDidAddFence:(BBFenceInfo *)fenceInfo;
-(void)BBLocationManagerDidFailedFence:(BBFenceInfo *)fenceInf
-(void)BBLocationManagerDidEnterFence:(BBFenceInfo *)fenceInfo
-(void)BBLocationManagerDidExitFence:(BBFenceInfo *)fenceInfo;

Example Project

Downloading the full source code or checking out using git will provide you the example project. Give it a try, dont forget to specify a location in the iOS Simulator's Debug > Location menu if you aren't testing on real device.

Other Reads

Issues and Contributions

Please raise an issue here if you find any bug, I'll try to resolve it asap. You can also make pull requests if you want.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Using BBLocationManager in your project?

If you are using this library in your project, and happy about it, please send me a email and let me know, I'll add a references of your app. Thanks :)

Comments
  • It is not work  when app is in background.

    It is not work when app is in background.

    I am developing an app that work in background. I add a geofence and put the app in background. After that BBLocationManagerDidEnterFence method will not work. Why? Is it doesn't work in background mode?

    opened by JacobVinu 4
  • Location issue in region

    Location issue in region

    I was tried to add two nearest location but it was not allowed. When i was tried this instead of add two location it is display message below message.

    Log for issue. [BBLocationManager] Fence already exist for area: 9,Pin-Up Bowl ---- inside: Restaurant_2 2018-02-09 17:04:53.593570+0530 demo[67141:434050] Added GeoFence: { BBeventTimeStamp = "09-02-2018 17:04:53"; BBeventType = BBFenceEventRepeated; BBfenceCoordinate = { BBRadious = 100; latitude = "38.65574645996094"; longitude = "-90.2991943359375"; }; BBfenceIDentifier = "Restaurant_2"; } 2018-02-09 17:04:53.657464+0530 demo[67141:434050] [BBLocationManager] Fence already exist for area: (null) ---- inside: Restaurant_2 2018-02-09 17:04:53.657959+0530 demo[67141:434050] Added GeoFence: { BBeventTimeStamp = "09-02-2018 17:04:53"; BBeventType = BBFenceEventRepeated; BBfenceCoordinate = { BBRadious = 100; latitude = "38.65574645996094"; longitude = "-90.2991943359375"; }; BBfenceIDentifier = "Restaurant_2"; }

    ==> check below for location if first 5 digits same then doesn't allow first location every time used second location . { lat = "38.655743"; lng = "-90.29864"; restID = 7; restoName = "Restaurant_1"; }, { lat = "38.655746"; lng = "-90.29919"; restID = 9; restoName = "Restaurant_2"; }

    opened by nileshordex 2
  • Incorrect keys in Location updates dictionary

    Incorrect keys in Location updates dictionary

    Hey there,

    Thanks for the awesome library :)

    I have one issue and one suggestion... If I may...

    /**
         *   Gives an Location Dictionary using keys BB_LATITUDE, BB_LONGITUDE, BB_ALTITUDE
         */
        public func bbLocationManagerDidUpdateLocation(_ latLongAltitudeDictionary: [AnyHashable : Any]!) {  }
    

    Those keys are incorrect. The keys used in the dictionary seem to be latitude, longitude and altitude.

    Suggestion:

    Maybe make some of the the delegate methods optional so we don't have to include all of them in the delegate class :)

    Cheers!

    opened by byroncoetsee 2
  • Location Accuracy

    Location Accuracy

    Hey there,

    Thanks for the library :)

    Question: After I've set my desired accuracy, can I be guaranteed the any time I call getCurrentLocation, the returned location will have that accuracy? If not, is there a way to retrieve the current accuracy?

    Thanks

    opened by byroncoetsee 1
  • continues location start at same spot

    continues location start at same spot

    I was stay on same place and don't move device then continues location got if change the position then after we got the notification in continues location am i right? if Yes so how to resolved it.

    opened by nileshordex 0
  • Continues location get in simulator but not in real device after terminated

    Continues location get in simulator but not in real device after terminated

    I was set continues location get method so continues location get in simulator, but not in real device some time we got the location but some how stop this method and again start continues location get. These all scenario in after terminated app not in foreground or background. Please help me this issue.

    opened by nileshordex 0
  • Doesn't work getContiniousLocationWithDelegate

    Doesn't work getContiniousLocationWithDelegate

    When i call is method then doesn't work Continues Location get. ------> BBLocationManager *manager = [BBLocationManager sharedManager]; [manager getContiniousLocationWithDelegate:self]; [manager getSingificantLocationChangeWithDelegate:self]; [self addFenceGeoatCurrentLocation]; ------>

    So need to help with me how to solved this issue.

    opened by nileshordex 0
  • Comments shows warning on

    Comments shows warning on "@param" and "@return".

    Comments shows warning on "@param" and "@return" everywhere in the class. So please remove the "@" sign or change something to fix the warning. This might because of xCode 10. Please the attachments here below. There are lot more warning in the file if you compile it using xcode 10. screen shot 2018-10-16 at 11 08 06 am screen shot 2018-10-16 at 11 08 50 am

    opened by ods2-hamid 1
Releases(1.0)
Owner
Benzamin Basher
Apple geek, Urban Terrorist, table-tennis lover, tech & gadget lover, ex-(wanted to be a)hacker, JS admirer, secret-crash on game development & VFX. Fun loving.
Benzamin Basher
Enumerate Location Services using CoreLocation API on macOS

SwiftLiverpool Description This tool leverages the CoreLocation API on macOS to enumerate Location Services data. You need to enable "Location Service

Justin Bui 4 Aug 20, 2022
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Daniele Margutti 3.2k Dec 30, 2022
The most power-efficient and lightweight iOS location manager for Swift and ObjC

IngeoSDK for iOS Overview IngeoSDK is a power-efficient location manager for iOS (Swift and Objective-C), which extends and improves CoreLocation. It

IngeoSDK 99 Feb 28, 2022
Easily get the device's current location on iOS.

INTULocationManager makes it easy to get the device's current location and is currently heading on iOS. It is an Objective-C library that also works g

Intuit 2.6k Dec 21, 2022
CLI for setting location in the iOS simulator

set-simulator-location This is a simple CLI for easily setting the location of the currently running iOS Simulator. Usage Set a specific latitude and

Mobile Native Foundation 619 Jan 6, 2023
Application that displays current weather at a random location. iOS 14.0 or newer. SwiftUI.

Elseweather App that displays current weather at a random location. Description Elseweather was created as a student/research project with no practica

Ярослав 11 Dec 15, 2022
An iOS app to display quarantine classification information based on users location

ph covid19 Quarantine Classification Automatically check quarantine classification based on your location Tech: MVVM Observer Binding MapKit, CoreLoca

Carlos Rivas 0 Nov 15, 2021
Location Weather Demo With Swift

LocationWeatherDemo Здравствуйте! Для того что бы проект корректно работал установите pod's. О проекте: 1) На первой странице можно увидеть погоду в л

German Khodyrev 0 Dec 8, 2021
Simulate GPS location system-wide

locsim A tool to simulate GPS location system-wide. This tool simulates GPS location natively without any runtime injection, and it's how Apple do it.

udevs 47 Dec 29, 2022
A simple map with the location of the user and the control of permissions

Proposal The project is based on implementing a simple map with the location of

Raúl Pedraza León 0 Dec 26, 2021
Shows the ISS live location.

ISSLive Shows the ISS live location. Challenge tasks: Project structure Create repo. Setup project. Organize files following the MVVM pattern. Install

Alejandro Trejo Flores 0 Feb 2, 2022
An original project making use of custom UITableViewCells, date formatting, json parsing, and handling user location.

SunTimes An original project making use of custom UITableViewCells, date formatting, json parsing, date and time formatting based on the json data, an

David Chester 0 Feb 8, 2022
Traccar Manager for iOS

Traccar Manager for iOS Overview Traccar Manager is a mobile application to manage GPS tracking devices. It requires a Traccar server instance to work

Traccar 86 Dec 15, 2022
Simple library to detect motion type (walking, running, automotive) and count users steps. This library will make motion detection much more easily.

SOMotionDetector Simple library to detect motion for iOS by arturdev . Based on location updates and acceleration. ###Requierments iOS > 6.0 Compatibl

Artur  Mkrtchyan 1.1k Nov 25, 2022
iOS and  Watch app to find city bicycles to rent in your city

Bike-Compass Bike Compass is a full-featured city bicycle finder app for iOS. Using a bike is enjoyable, that is why our app is fast, beautiful, and d

Raul Riera 80 May 18, 2022
Open-source iOS application written to explore Swift in its early days

Cepp iOS application written in Swift. Icon by: Rodrigo Nascimento (tks :D) IMPORTANT: *This project uses CocoaPods as the dependency manager, make su

Filipe Alvarenga 14 Sep 12, 2022
Contains the swift rewrite of Find My Bus NJ iOS App

FIND MY BUS NJ 2 An app for tracking NJ Transit bus times. Dependancies Alamofire SwiftyJSON PKHUD Fabric Getting started Install fastlane and imagema

null 44 Dec 10, 2022
A native iOS client to map the Pokemon around you!

Pokemap client for iOS This is a client for the Pokemap server (https://github.com/RocketMap/RocketMap) iPokeGO is now officially available on the App

Dimitri Dessus 640 Oct 12, 2022
🗺️ MAPS.ME — Offline OpenStreetMap maps for iOS and Android

MAPS.ME MAPS.ME is an open source cross-platform offline maps application, built on top of crowd-sourced OpenStreetMap data. It was publicly released

MAPS.ME 4.5k Dec 23, 2022