Giter Site home page Giter Site logo

ttlocationhandler's Introduction

#TTLocationHandler

This is the evolution of my experimentation and testing the best manner of use of location services in iOS. It started with a base derived from the code and all that I learned from a series by Mark at The Long Weekend Website.

You can find that blog, and the original classes here: http://longweekendmobile.com/2010/06/30/location-region-data-in-background-on-ios4-iphone/

That code was released "via an MIT-style license (=do whatever you want with it, but don't blame me, and include my copyright notice in the code if you change/redistribute/use)." Everything in the TTLocationHandler class files follow suit and full credit is given to Long Weekend, LLC for helping to get my own understanding of location handling off the ground.

In this repository, you will find one class header and implementation that you want to import if you intend to try it in your own project. The entire class is comprised of the files TTLocationHandler.h and TTLocationHandler.m. The other classes are all just a quick mashup to demonstrate use and check that all works as intended.

##Event Handling Notes:

  • Handler receives the location events from the locationManager, checks for accuracy and time since last event.
  • If the last event was stored a set interval earlier, and is within the required accuracy, the location info is accepted and saved.
  • Saving a location from a location event is done in a property of the handler and in the standardUserDefaults. Saving in the defaults allows any class in the project to get the most recent location without having to import, hold reference to, or even to know anything at all about the locationHandler class.
  • If the time since previous saved event is outside our parameters and the new location is inaccurate, it is stored in a queue array and considered for acceptance only if another more accurate location isn't received. Ten seconds is allowed to wait for more accurate event, and max tries of 10 before giving up and best available is accepted.

##Power usage and Background Operation Notes:

  • The default is allow continuous updating of location when the application is in foreground. This can be set on or off.
  • The default is to switch to significantUpdates only when in the background. There is a setting for continuous updates in background when the device is plugged into external power.
  • You can also set continuesUpdatingOnBattery. Use this responsibly as it will impact batter life considerably.
  • The locationManager distanceFilter is increased at highway speeds as events come in scary fast and it seems a waste of activity.
  • Make note of the backgroundTaskIdentifier assignment. The operations were very unreliable before I included this. I recommend using the begin and end task lines where ever you address responding to the location notification. I also recommend putting those operations on a global queue.

All of the paramaters are configurable including accuracy required, distance between location events, max tries for accuracy, wait time for accuracy, continue in background, highway mode. I have tried many variations and the defaults here are what I have had the best results with.
My experience, in testing on several devices, is very little impact on battery life and reliable tracking with no serious issues. I am interested to see what improvement might be made by others.
Please fork and add your input. Any ideas will be considered for push. My aim is to improve what I have and share it for all interested.

ttlocationhandler's People

Contributors

dsdavids avatar

Watchers

Kerry Munz avatar

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.