Giter Site home page Giter Site logo

dtlocationmanager's Introduction

CocoaPod platform   CocoaPod version   License MIT

DTLocationManager

DTLocationManager is simple and lightweight wrapper for CLLocationManager API. It encapsulates filters for

  • Horizontal accuracy
  • Location timestamp

Where am I?

Often you'll need to get current user location once. You can use DTMomentaryLocationManager for this:

    self.locationManager = [DTMomentaryLocationManager new];
    __weak typeof(self) weakSelf = self;
    [self.locationManager startWithBlock:^(CLLocation *location, LocationResultType result) {
        switch (result) {
            case LocationResultTypeFailure:
                // Failed to get location, presumably services disabled, or hardware does not have GPS
                break;
            case LocationResultTypeTimedOut:
                // Criterias were not met in the desired time, but best location we got is in location variable
                break;
            case LocationResultTypeSuccess:
                // Got location
                break;
        }
    }];

Defaults used:

  • horizontalAccuracy - 100 meters
  • maximum timestamp age - 5 minutes

You can change them, however you like

self.locationManager.desiredHorizontalAccuracy = 50;
self.locationManager.timestampMaxAge = 120;

Where am I over time?

Sometimes you'll want location updates to be received over time. The API is similar, but we'll use DTPeriodicLocationManager for this.

    self.locationManager = [DTPeriodicLocationManager new];
    __weak typeof(self) weakSelf = self;
    [self.locationManager startWithBlock:^(CLLocation *location, LocationResultType result) {
        switch (result) {
            case LocationResultTypeFailure:
                // Failed to get location, presumably services disabled, or hardware does not have GPS
                break;
            case LocationResultTypeSuccess:
                // Got location
                break;
        }
    }];

Completion block will be called continuously, until you stop location updates by calling

[self.locationManager stop];

Design decisions

Most of location managers available on GitHub are cumbersome, or are built using Singleton pattern. The pattern is fine, but CLLocationManager was never meant to be used as a singleton. Which is why this location manager does not force you to use singleton pattern, if you need to get location updates.

Another thing to note is that all CLLocationManagerDelegate methods are trampolined to optional delegate property on DTBaseLocationManager. So if you need heading, iBeacon, or some other delegate methods, you'll be able to implement them in another object without any trouble.

Requirements

  • Xcode 6.3 and higher
  • iOS 6 and higher
  • Mac OS X Mavericks (10.9) and higher
  • ARC

Installation

Install using CocoaPods,

pod 'DTLocationManager', '~> 0.2.3'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.