Location-Based Services will be worth $10 Billion by 2016 GigaOm
Location-Based Services (LBS) are a revolutionary, but still fresh from the oven, breed of services that has grown tremendously to carve itself as a new industry in just a few years.
Location-Based Services is the next step in the evolution for search, on the web and mobile, adding the Location Context (where am I or things around me) for search. To quote from Wikipedia on the definition of LBS:
A Location-Based Services (LBS) is an information or entertainment service, accessible with mobile devices through the mobile network and utilizing the ability to make use of the geographical position (read Geocodes or Latitude/Longitude) of the mobile device.
You may have already used LBS when on Twitter, Facebook, Foursquare, Groupon, or visit hyperlocal web pages such as
Wcities.com, Yelp.com, Qype.co.uk
, andEventful.com
to find the top venues in the city or events happening in your city.
Want to know how the location is determined? Continue reading the chapter to understand the different location detection methods and which one is the right choice for you.
In this chapter, we shall understand:
Location-Based Services
Buzz words in the LBS Industry
Applications of LBS and common use cases
How Apple uses LBS in iOS devices
GPS Global Positioning System
Indoor and outdoor navigation with GPS
So let's get on with it...
The concept of Location-Based Services (LBS used as reference henceforth in the rest of the book) refers to services that integrate a mobile device's location with other topical information to provide added value to users.
Consider a weather app that shows weather information for all of the cities in the United States of America. For a user living in San Francisco, this behemoth of information is not very helpful, unless he can see the exact weather information for his city. This is achieved by mashing up the weather information with the user's location (generally obtained using a GPS system).
Another example of LBS are local search websites such asWcities.com
that present a user with hyper local (read local, nearby or neighborhood-centered) information on hotels, restaurants, shopping, and entertainment venues that makes a user feel connected with the type of information shown to him/her.
The core requirement for LBS is GPS (covered in more detail shortly), a space-based satellite navigation system developed and maintained by the United States of America. Other countries have similar systems too; Russia has Russian Global Navigation Satellite System (GLONASS), Europe has the Galileo Positioning System, India and China are working on their own positioning system as well, but GPS remains the most popular and preferred choice for device makers and application developers worldwide.
Anyone can use GPS freely by using either a Personal Navigation Device (Garmin, TomTom), or an In-Car Navigation System (Ford Sync), or by using a Smart Phone.
On the mobile front, LBS also use Google Maps and other cartographic API services extensively (even in cases where the device does not support GPS). This is done using rich map data and Geocoding services. Using Geocoding and smart algorithms, a user's position can be guessed or approximated. Mobile Operating Systems, such as Android, further the cause of LBS by integrating locations into the Core OS, where the location can be fetched, used, and updated by all applications.
Apple iOS leads the pack with the best software API support, coupled with excellent hardware and positioning system integrated in the Apple Eco System. It also has network-based Assisted GPS (AGPS) that uses the network's data connection in the case of weak GPS signals as well as Apple's own Wi-Fi location database. iOS developers have a plethora of location tools and API to work with.
In short, LBS can be described as a combination of two components, Location Providers and Location Consumers, with GPS, AGPS, iOS API, and Google Maps API as the location providers and GPS receivers, mobile phones, and websites as the consumers of location data.
The concept of Location-Based Services (LBS used as reference henceforth in the rest of the book) refers to services that integrate a mobile device's location with other topical information to provide added value to users.
Consider a weather app that shows weather information for all of the cities in the United States of America. For a user living in San Francisco, this behemoth of information is not very helpful, unless he can see the exact weather information for his city. This is achieved by mashing up the weather information with the user's location (generally obtained using a GPS system).
Another example of LBS are local search websites such asWcities.com
that present a user with hyper local (read local, nearby or neighborhood-centered) information on hotels, restaurants, shopping, and entertainment venues that makes a user feel connected with the type of information shown to him/her.
The core requirement for LBS is GPS (covered in more detail shortly), a space-based satellite navigation system developed and maintained by the United States of America. Other countries have similar systems too; Russia has Russian Global Navigation Satellite System (GLONASS), Europe has the Galileo Positioning System, India and China are working on their own positioning system as well, but GPS remains the most popular and preferred choice for device makers and application developers worldwide.
Anyone can use GPS freely by using either a Personal Navigation Device (Garmin, TomTom), or an In-Car Navigation System (Ford Sync), or by using a Smart Phone.
On the mobile front, LBS also use Google Maps and other cartographic API services extensively (even in cases where the device does not support GPS). This is done using rich map data and Geocoding services. Using Geocoding and smart algorithms, a user's position can be guessed or approximated. Mobile Operating Systems, such as Android, further the cause of LBS by integrating locations into the Core OS, where the location can be fetched, used, and updated by all applications.
Apple iOS leads the pack with the best software API support, coupled with excellent hardware and positioning system integrated in the Apple Eco System. It also has network-based Assisted GPS (AGPS) that uses the network's data connection in the case of weak GPS signals as well as Apple's own Wi-Fi location database. iOS developers have a plethora of location tools and API to work with.
In short, LBS can be described as a combination of two components, Location Providers and Location Consumers, with GPS, AGPS, iOS API, and Google Maps API as the location providers and GPS receivers, mobile phones, and websites as the consumers of location data.
To understand how LBS work behind the scenes, let's take an example of the most common use of LBS, that is, how Google.com uses LBS for its search.
1. Fire up your Safari Browser and navigate to http://google.com.
2. Enter Hotels in San Francisco as the search key and hit Enter.
3. You are presented with results from the Google Places database, as shown in the following screenshot:
4. You get similar (but formatted) results from the iPhone browser search, as follows:
5. Scroll further down the page to see the actual results (following screenshot). The preceding screenshot is an ad-supported display that shows up on each search query (that's how Google makes money).
When you searched for Hotels in San Francisco on Google, Google first presented you with the hotels in its database (Google Places database) that matched the query for hotels as well as for San Francisco; this is done by Geocoding those hotels and storing it in a Geographic Information System (GIS) -aware database.
The mobile search on Google via the iPhone makes it more relevant to the user as it presents a nice map with the hotels plotted on the map and the hotels' details below (as seen in the preceding screenshots). Other mobile-optimized websites present similar content based on the location detected from the mobile phone.
As the book deals with iPhone location-aware apps, it is a good time now to understand the buzzwords and key terms used in the Location-Based Industry, so that term such as Check-In, GPS, AGPS, Geocoding, Reverse Geocoding, Geo fencing are made familiar to the reader.
GPS: Global Positioning System — A set of satellite systems that provides global navigation data including location and time.
GLONASS: Global Navigation Satellite System Russian Navigation System.
AGPS: Assisted GPS — Mobile network-assisted GPS system, which uses the mobile network as a fall back in areas of poor GPS coverage.
GIS: Geographic Information System — A system for storing, processing, and retrieving geographically-aware data. It uses the user interface (usually Raster Map Images) for easier management. A GIS typically involves both hardware and software.
Spatial Database: A database management system that is used for storing, querying, and fetching geographically-aware databases and is used in conjunction with GIS for data management.
Geocodes: The latitude and longitude pair used to refer to a point on the earth's surface.
Geocoding: The process of converting a text address to Geocodes using Geocoding services such as GeoNames or Google Maps API.
Reverse Geocoding: The process of converting Geocodes to a text address.
Geo Fencing: Geo Fencing refers to the process of device-based alerts or notifications when entering a virtual geographical area. This geographic area can be a block, a lane, a neighborhood, a city, and so on, based on the application logic.
Check-ins: Made popular by start-up companies such as Foursquare and Footfeed, check-ins refers to the process of confirming that you actually entered/checked-in to a place via a mobile phone app.
GeoTagging: GeoTagging is the process of assigning Geocodes (latitude-longitude pair values) to any news article, blog post, twitter tweet, photo, or any other web resource, so that location-based searches can be performed on them.
Location-Based Advertising (LBA): Location-based advertising is a new paradigm in web and mobile ads, which are triggered by the location of the mobile device. Location-specific adverts for deals, events, movies, shopping, and restaurants offers are all possible with LBA.
Augmented Reality (AR): Augmented Reality is an exciting visual manipulation (augmentation) of the real-world environment (usually captured via a mobile phone camera) combined with computer generated (location-based) multimedia elements (pictures, audio, videos, 3D animation) usually in real time, giving the user a perception of superimposition of computer-generated elements onto the real world.
HTML5: HTML5 is the new version of the Hypertext Mark-up Language that is under heavy development at W3C and browser companies such as Mozilla, Apple, Google, and Microsoft. HTML5 is poised to bring in a new and better way of writing HTML pages using standardized tags that not only help the web developers maintain code reusability, but also makes it easy for search engines to semantically extract information from such HTML5 websites.
The primary use of LBS combined with GPS was and will remain the same, that is, navigation. There are new and exciting (and sometimes crazy!!) ideas being implemented in LBS every other day. Research and markets (http://www.researchandmarkets.com/) has predicted a market forecast of US $10 billion for the LBS industry in 2015, from $2.8 billion in 2010. Gigaom (http://gigaom.com), which is a technology blog by a Silicon Valley veteran Om Malik, has similar views on the LBS industry.
Government and military, navigation, and commercial industries such as advertising, social networks, and web portals are the primary consumers of LBS. GPS, in fact, was funded by the US Department of Defense (DOD) and still is maintained by DOD. It was initially designed for military use. In the late 1980s and early 1990s, it was opened up for civilian use. Let's review the common use cases:
The US military uses GPS for navigation purposes including troops' movements. Target tracking weapons use GPS to track their targets. Military aircrafts and missiles use GPS in various forms.
The government uses GPS for emergency services such as the US 911 service, which uses GPS to pinpoint the caller's location for faster pinpointing of the user and for providing emergency service on time.
Navigational GPS units that provide car owners with directions to destinations are the biggest commercial users of GPS. Air traffic control, seaport control, freight management, car and transport tracking, and Yellow pages data management (local search) are other commercial uses of GPS.
Note
Interestingly, GPS is also used for time synchronization. The precision provided by GPS improves the time data by 40 billionths of a second.
If you have the new iPhone 4S and are overwhelmed by Siri and its intelligence, then you should know that GPS and/or other location-detection methods play an important role in making the intelligent decisions.
The Apple iPhone is a revolutionary Smartphone launched by Apple on June 29 2007. Since its launch, it has gone on to become the most popular Smartphone, carving a new market for itself. It has also seen revisions almost every year, with the current version being the iPhone 4S, launched in October 2011.
Besides the iPhone, Apple has other products, now branched together as iOS devices, which include iPod Touch and iPad 2, and they have all the features of the iPhone besides the fact that you cannot make calls with them. Apple has provisioned the iPhone 4 with the following location-supported hardware that helps the device establish location positioning for the core OS and apps:
AGPS
Digital compass
Wi-Fi
Cellular location
The iPod Touch uses Wi-Fi (Apple's location database) and the Maps application to approximate the user's location. The iPad uses Wi-Fi and the compass for location, while the iPad 3G uses AGPS, Digital Compass, Wi-Fi, and Cellular locations, just like the iPhone 4. The following table summarizes the location features in all the iOS devices:
Device |
AGPS |
Digital compass |
Wi-Fi |
Cellular |
---|---|---|---|---|
iPhone 4 |
Yes |
Yes |
Yes |
Yes |
iPod Touch |
No |
No |
Yes |
No |
iPad |
No |
Yes |
Yes |
No |
iPad 3G |
Yes |
Yes |
Yes |
Yes |
Apple uses this hardware for location detection of the user on the software side; Apple's new advertising product iAd may also be used for location tracking of the user.
However, for the safe keeping of the user's location data, the user has to opt-in for the location tracking, so that iOS and third-party applications can use his/her location. Most apps show an alert message asking for user confirmation to use their location data. The iAd network also has an option where users can elect to share their data with the service via http://oo.apple.com
The Core Location API in the Apple iOS SDK is used for communicating with device hardware to get user location information. We will cover Core Location in the forthcoming chapters.
Core Location also supports direction-related API calls, the magnetometer in the iOS device reports the direction in which a device is pointing. Besides the heading, the GPS hardware can also return where the device is moving; this is known as its course. This is used by navigation apps to show continuous user movement. The Core Location framework contains various classes to handle the heading and course information. More details on this as we move along the course of the book!
To turn on or off the Location Tracking by inbuilt and third-party apps in your iPhone (for iOS version 5), carry out the following steps on your iPhone:
1. Go to Settings | Location Services.
2. Select the apps that you want to allow usage of your location information.
3. To reset the Location Warnings made by applications such as Camera or Compass, go to Settings | General | Reset and select Reset Location Warnings.
4. In iOS 5, you can also switch location tracking for System Services, including iAds, Compass, Traffic, Time Zone Settings and Diagnostics, and Usage. These settings can be found at Settings | Location Services | System Services.
Note
Note that this works for iOS version 5 (tested on iOS 5). For iOS 4.x, please refer to the official Apple documentation at http://support.apple.com/kb/HT1975
iOS versions prior to iOS 4.3.3 had a bug with the location settings, where the user's location information was stored on the iPhone, backed up to iTunes, and was open to hacks by third-party applications. Apple removed these bugs in version iOS 4.3.3, after a lot of hue and cry from security watchdogs. With the new release, the user's location history is deleted every time the user switches the location services off. Apple also reduced the cache size so less location information of the user will be cached on the device. In iOS 5, the location history of the user is encrypted, so third-party applications will not be able to read location information without the right authorization.
Let's learn a bit more about GPS, as it powers all the current LBS implementations. If you are building the next generation navigation software or your own mapping applications, it's the right time to know more about GPS and how it works, so that it can help you make key decisions for your application.
GPS has three major components, as depicted in the following diagram, the user segment (GPS receivers, mobile phones, car navigation units), the space segment (24 satellites in orbit), and the GPS control segment having its base on Earth, with the Master Control Station (MCS) in Colorado Springs, Colorado (so now you know where to head to get a clear signal!).
The user segment comprises the GPS receivers embedded in millions of military equipment, almost all cell phones these days, aircraft, and car navigation systems.
Space segment comprises the satellites orbiting the earth. The 24 satellites move on six different orbits around the earth at a distance of 20,200 km.
The satellites move in a manner that at every point of the earth's surface, at least five and at most 11 satellites are visible over the horizon for maximum accuracy.
The control segment is the base on Earth that controls the functioning of the GPS satellites and passes on the administrative commands such as correcting the satellite orbit and internal data. Several monitoring stations receive the satellite signals based on their location; they are synced with atomic clocks to calculate the correction data. This corrected data is then sent to the Master Control Station.
LBS implementation is based on Push Services or Pull Services, depending on the way location information is retrieved.
Push Services imply that the user receives location information without having to actively or continuously keep requesting for it. However, the user consent is acquired beforehand. For example, the navigation software in your car will require your consent to use your location information when you switch it on. However, as you drive your car around town, your new location will automatically be acquired via Push Services.
Some more examples of Push Service include Emergency Alert System (in case of terror attacks), location-based advertising apps on your phone that notify you with deals, messages, and alerts on entering a new city or town.
Pull Services work on the on-demand principle. Your apps would request location information from the network on demand, usually on application load, but is not limited to other stages in the app. For example, a Restaurant Search app on your iPhone would request location information when it loads, and you can change the location via the settings page of the app. In this way, the application pulls location information when needed and not continuously in the background.
In the forthcoming chapters, we will be building apps by mostly using the Pull Services, including a local search app and an events app that will pull location information on demand and mash it with information retrieved via Web Services.
There are alternative ways to detect the location through mobile phone devices using their Wi-Fi MAC addresses (access points that connect to the Internet) to determine the location. Wi-Fi-based positioning returns the approximate location, which may not be the exact latitude-longitude pair, but it would be the closest.
Companies such as SkyHook Wireless, and Google (with Google Latitude) were the first to provide this service. Apple launched a similar service in April 2010 with its own Location Database for devices having iOS version 3.2 and above.
Skyhook Wireless' location is pretty much public, with provisions for end users to add their location data to its database via a web interface, which is then available to all implementations of SkyHook wireless API users. Their database uses over 250 million Wi-Fi access points and cellular tower information for location analysis. Skyhook deploys data collection vehicles to conduct the access point survey, much similar to the manner Google Street views cars. The accuracy provided by SkyHook Wireless is ten meters. To know more about SkyHook Wireless coverage, visit http://www.skyhookwireless.com/howitworks/coverage.php
Google Latitude uses a mix of Wi-Fi, GPS, and cell tower-based location-positioning methods. It is tightly integrated with Google's Mobile Operating System — Android, and its Google Maps application. It works on PCs, Laptops, and mobiles alike. The Google Latitude app for iPhone is available from the Apple app Store from http://itunes.apple.com/us/app/google-latitude/id306586497; it supports automatic location detection coupled with automatic check-ins to nearby places, as you move around.
Low cost or price-sensitive mobile phones often come without GPS and Wi-Fi. These phones are meant to do what mobile phones are intended to be used for — Talk. However, the location of the user can still be detected on such phones using cellular towers. Cell ID Positioning and cell tower triangulation are two different ways to get location information from cell towers. Cell ID result accuracy is only 200-1000 meters, hence it is used as the last option for most location detection methodologies.
Cell ID Positioning uses your mobile network's cell tower to find your location. This involves the nearest tower your phone connects to in order to let you place calls. Cell tower triangulation, on the other hand, uses all the Cellular Towers around you to calculate your position based on the signal strength your phone receives from each of the towers. Triangulation is more accurate, but a slower process.
The iOS SDK has a region monitoring API that we will discuss in later chapters. This API is CLRegion
, which monitors the iPhone location and triggers an alert if you enter or leave a region. It works by using the Cellular Tower position as the trigger. When the iOS device detects a different Cellular Tower using the Triangulation technique to ascertain that the user has indeed crossed or entered a region, it triggers an alert to the application. This is an efficient way of location tracking without using GPS (and hence, more battery juice).
Note
It is important to acknowledge privacy and security issues for end users while developing your applications and choosing the type of location detection and storage. In April 2011, it was discovered that Apple kept an unencrypted location database on your iPhones, even if the Location Setting was turned off. This file could tell any hacker where you have been and the timing details. Apple rectified this with a software upgrade, but it has been an eye opener for user privacy and security concerns.
Loki is a SkyHook Wireless product targeted at website owners to help them locate their visitors. It is a JavaScript implementation done using the same SkyHook algorithms as on the mobile devices.
1. Go to http://loki.com/findme with your favorite browser.
2. You will get a permission request from a Java Applet, as shown in the following screenshot:
3. Wait for a few seconds and you should see your location detected.
4. If your Wi-Fi is not registered with SkyHook wireless, then you can do so by adding the same on http://www.skyhookwireless.com/howitworks/submit_ap.php
Loki.com uses a proprietary JavaScript code and uses a Wi-Fi Positioning system to determine your location. Users can also submit their Wi-Fi MAC ID to be included in the Loki database.
Loki also has a developer API that can be used by website developers to integrate a location in their websites.
Google Maps API is the most powerful mapping and Geocoding API, used by millions of developers to integrate locations and maps in their Web and mobile applications. It provides a rich set of APIs for Directions, Maps, and Geocoding. We will focus on the Geocoding API in Google Maps Version 3, as that is what we are interested with in this book; the rest is beyond the scope of this book.
Geocoding, as described earlier, is a process of converting addresses into geographic coordinates (latitude and longitude pair). Google Maps uses these co-ordinates to plot them on a map. Google Maps API provides options for both Geocoding and Reverse Geocoding.
The Geocoding API is a RESTful API that can be consumed with the following API call http://maps.googleapis.com/maps/api/geocode/output?parameters where the output can be json/xml
and the parameters can use any one of the following:
address
(required) or latlng
(required)
bounds
region
language
sensor
(required)
An example of a Geocoding request for South Park in San Francisco, CA, USA is constructed as follows:
http://maps.googleapis.com/maps/api/geocode/json?address=South+Park,+San+Francisco&sensor=false
This returns the following results:
{
"results" : [
{
"address_components" : [
{
"long_name" : "South Park",
"short_name" : "South Park",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "San Francisco",
"short_name" : "SF",
"types" : [ "locality", "political" ]
},
{
"long_name" : "San Francisco",
"short_name" : "San Francisco",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "San Francisco",
"short_name" : "San Francisco",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94107",
"short_name" : "94107",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "South Park, San Francisco, CA 94107, USA",
"geometry" : {
"location" : {
"lat" : 37.78160380,
"lng" : -122.39389940
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.7904220,
"lng" : -122.3778920
},
"southwest" : {
"lat" : 37.77278450,
"lng" : -122.40990680
}
}
},
"types" : [ "neighborhood", "political" ]
}
],
"status" : "OK"
}
Note
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
The values in bold are the ones of real importance to us, that is, the geometry | location | lat and the geometry | location | lng values. We will also be using the Geocoder provided in the iOS SDK in the coming chapters. If you are developing your apps in HTML5 for web and mobile, then you can check the Google Maps API at http://code.google.com/apis/maps/, as the W3C Geolocation standard has been implemented in Google Maps API.
Apple iOS Map Kit API uses Google Maps as the underlying technology to Geocode and reverse Geocode. We will cover Map Kit extensively in Chapter 4, Using Maps — Mapkit, but now is a good time to play with Google Maps API to get an overview of how things work.
Navigation functionalities in cars, airplanes, rail, and mobile phones are mostly optimized for on-the-move functionality, it assumes that the user of such services tends to exhibit movement from one place to another with time; this is classified as Outdoor Navigation, implying navigation done outside homes, offices, malls, any place not confined to a building or large area.
This is where Indoor Navigation sets in, while GPS and other positioning systems have high coverage and accuracy, they fail when you are indoors, in a mail or a shopping complex, even airport lounges, stadiums, office complexes, as the radio signals from GPS transmitters cannot penetrate walls. Indoor Navigation works in such places, using techniques dissimilar to outdoor navigation; in short, no GPS for Indoor Navigation.
There are various implementations of Indoor Navigation, some using Infrared techniques, some using Radio signals (RFID) , and another implementation using Ultrasound. Companies such as VisioGlobe (http://visioglobe.com) offer an SDK for Indoor Navigational purposes. Another company WiFiSLAM is building a Wi-Fi-based solution. While the market for Indoor Navigation is quite big and the outlook for growth is very positive, the implementation and standardization is at a very nascent stage, partly due to the fact that a generic solution that fits all is not possible for Indoor navigation. Additionally, interactive kiosks at malls, airports, convention centers solve the problem of information management for visitors.
Google Maps on Android now include Indoor Navigation that allows you to navigate through floor plans for Airports, Shopping Malls, and Retail Stores. More information at http://googleblog.blogspot.com/2011/11/new-frontier-for-google-maps-mapping.html
1. What are the various methods of location detection?
a. Detect and Store
b. Push and Pull
c. Device hardware and software
2. To conserve device battery consumption, what method of location detection will you employ and why?
a. No Location
b. Pull methods
c. Push methods
3. In case there is no source of location detection, either via GPS, WIFI, or Cell ID triangulation, how will you model your Location-based app?
a. I am out of luck; need to remove the location feature completely
b. I will assume location information
c. I will ask the user and convert the user input to relevant location values, based on pre-set rules
In this introductory chapter, we have identified how LBS work — the buzzwords behind all things location and the importance of GPS.
Specifically, we discovered:
LBS, and its applications in the real world
How Apple uses Location in its iOS devices
GPS how it works
Non-GPS-based solutions for location
We also discussed new potentials in LBS markets — that of Indoor Navigation.
Now that we've got our feet grounded in location, we can move to the next chapter that introduces Apple's Xcode IDE and HTML5-based app development tools.