Posts Tagged ‘geolocation’

Is a consumer smartphone GPS good enough?

When I presented at OSCON  (O’Reilly’s Open Source Conference) in Portland, Oregon this last week on native Android GPS and Geolocation, I was repeatedly asked the question “is the GPS in smartphones good enough?” In general the answer is “yes”. But, I should back this statement up by looking at several everyday types of scenarios to help illustrate my answer.

What does accuracy mean? First lets briefly look at what accuracy means. Accuracy, in a technical sense, means you get a latitude, longitude and accuracy number from the GPS. Then you can draw a circle using the accuracy number as radius around the latitude/longitude point. It’s highly likely that your actual location is somewhere within that circle. It’s unfortunate that consumer GPS devices don’t also come with a probability factor that would indicate how much to trust the accuracy number. As it is, we will have to take it on a certain amount of faith that our real location is, in fact, somewhere within the accuracy circle.

Under absolutely perfect conditions your typical smartphone GPS chip will deliver around 3 meters (~10 ft) in accuracy for several minutes at a time.  Standing on the highest mountaintop in the Rocky Mountains with no clouds in the sky might come close to being a perfect condition. Under what I’ll call “average” conditions, which reflect everyday in-city usage patterns, you can expect accuracy from 3 – 150 meters (10 ft – 500 ft) or greater and the accuracy number typically fluctuates quite a bit over a period of minutes or hours. GPS signals are affected by anything that interferes with your smartphone receiving the weak transmissions from GPS satellites circling above us. Nearby trees, cars, buildings, big weather storms can all reduce accuracy, and so can being inside a building or underneath trees.

Getting the weather. Now back to the everyday scenarios I mentioned. I bet that most people who own smartphones use them to check the weather at least once per day. Furthermore, weather is typically affecting a large geographic area so the vast majority of forecasts cover cities, counties, States, regions or even entire countries.

I’m going to argue that for this scenario a GPS accuracy of 1000 to 2000 meters, or 0.6 to 1.24 miles is good enough to get started with a finding places app. Values in this accuracy range can be easily and quickly retrieved by a typical smartphone.

Finding places around me. Almost everyone that owns a smartphone has used an app to search for food, gas, groceries etc that are nearby.  There’s no hard written rule, but I think most people would agree that users who are looking for places around them tend to be less concerned about high levels of accuracy. Some applications let you choose target levels of accuracy such as 1 mile, 10 miles or even up to 100 miles for the search radius.

I’m going to argue that for this scenario, as well, that a GPS accuracy of 1000 to 2000 meters will also work perfectly fine.

Real-time driving directions. There are only a handful of applications that do this on smartphones, and even fewer apps do it really well. There’s a lot of hidden math involved in making everything look smooth to the user. These apps wipe away all of the complexity: simply give it a starting point and an endpoint and then away you go.  We’ve all used these types of applications so we know they work well the majority of the time even with the occasional navigational glitch, hardware lockup or low battery.

Social Media location. Hundreds of millions of people use location-aware social media apps every day. Some of these apps provide you with discounts, give-aways and coupons for retail locations that are around you.  For a typical big box store, it’s easy for an app to place you in the parking lot of a Target, Walmart, or a large supermarket and promotions can be based on your location, time of day or day of the week. It’s more challenging for stores with smaller storefronts to use targeted advertising unless someone is simply “in the vicinity”.  For example, tiny stores, kiosks and shops trying to compete in high traffic tourist areas have to compete with many other vendors. In a crowded marketplace area, even with 3 meter accuracy you could be standing next to four or more different storefronts.

A final few words

Hopefully these short examples have successfully illustrated the point that for typical consumer-focused applications smartphone GPS is simply good enough. Certainly there are many, many more scenarios that could be examined so I tried to pick the most common ones. Because of the lower accuracy requirements you can get less accurate results faster from a GPS. Speedy results can mean everything for today’s consumers who have high levels of intolerance for application delays.

The opposite is also true, the greater the accuracy requirements the longer it can take to get a more precise GPS measurement. As I’ve mentioned in my others posts on this subject, it’s takes time for a GPS device to get a fix and then it will try its best to hold onto it as you move around. I suspect that most consumers are significantly less demanding about accuracy as compared to commercial and government users. If consumers were more demanding then there would be a greater uproar about GPS accuracy.

To better understand how to make the most of location data check out the other posts I’ve written in the reference section below.

References:

Six most common use cases for Android GPS

How accurate is Android GPS? Part 1 – Understanding location data.

How accurate is Android GPS? Part 2 – Consuming real-time locations

Tags: , , , ,
Posted in Android, Open Source | No Comments »

If you are headed to OSCON, swing by my session on Mastering Android Geolocation. It’s a deep dive into the Android SDKs android.location package. If you’ve ever wanted to learn about the fundamental’s of the SDKs Geolocation capabilities then this is a must attend session. It will also give you a strong foundation to understand the underlying capabilities of the new Google Play Services SDK that includes Fused Location, Activity Recognition, and Geofencing APIs.

The presentation includes digging into the capabilities of my open source GPS Testing tool that lets you easily test different aspects of the Geolocation capabilities.

Here’s the details and I hope to see you there:

 Location, Location, Location: Mastering Android Geolocation
07/25/2013  5:00pm -  5:40pm PDT (40 minutes)
Room: Portland 251 (capacity: 200)
http://www.oscon.com/oscon2013/public/schedule/detail/28713

Tags: , , , ,
Posted in Android, Conferences, GPS | No Comments »

Where Part 1 focused on non-GPS enabled devices, Part 2 is totally focused on mobile web geolocation. The great news is that the usage of HTML5 location services along-side the fact that there is a GPS chipset in most, if not all, modern smartphones and tablets dramatically improves the chances of getting an accurate location. And, besides that fact — mobile geolocation is simply a lot of fun to work with.

I also want to point out that there are an increasing number of really good blog posts covering the topic of “how to use” the API that look at the nitty-gritty of how the code works. This post is different in that I’ve tried to focus on “how to build successful applications” with the API, and how to get the most out of the API so that you can successfully implement your unique requirements.

What’s different about desktop vs. mobile HTML5 Geolocation? With mobile you can access the GPS if it’s available. It’s important to note that in order to access a device GPS you have to set the optional enableHighAccuracy property in your code. Contrary to what is shown in some samples on the internet, you can use this property with both the getCurrentPosition() and watchPosition() functions.

//One time snapshot
navigator.geolocation.getCurrentPosition(
     processGeolocation,
     // Optional settings below
     geolocationError,
     {
         timeout: 0,
         enableHighAccuracy: true,
         maximumAge: Infinity
     }
);

//Tracking users position
watchId = navigator.geolocation.watchPosition(
     processGeolocation,
     // Optional settings below
     geolocationError,
     {
         timeout: 0,
         enableHighAccuracy: true,
         maximumAge: Infinity
     }
);

How accurate is it??? This is the million dollar question, right? When using enableHighAccuracy() on a phone where all the appropriate permissions have been selected and granted, I’ve typically seen accuracy readings as low as 3 meters (~10 feet) that were obtained within 10 – 30 seconds of kicking off the geolocation functionality. I’d consider that excellent for most consumer and retail applications. You should be aware that like any location-based functionality you will get spurious (abnormal) results that fall way outside the norm, and sometimes these results are wildly wrong.

I’ve seen claims that using the enableHighAccuracy() property slows down the phones ability to deliver a location. I’m going to argue that those claims are misleading. It is true that the GPS, itself, can take a significant amount of time to warm up and start delivering high accuracy results. For an in-depth look at that topic see my post on the Six Most Common Use Cases for Android GPS. However, there are conditions where simply enabling the enableHighAccuracy() property doesn’t affect the speed in which you can get the initial result. More on these topics below.

What is the best way to try out various configuration scenarios? I’ve built an HTML5 Geolocation Testing tool that can be used in browser, or it can be repurposed to work in PhoneGap or Titanium. It is a jQuery-based mobile application that includes a map and settings view were you can adjust all the different properties and try out different configuration scenarios. It’s a work-in-progress so I welcome suggestions and pull requests.

 Why HTML5 Geolocation rather than native? Applications using HTML5 Geolocation typically have slightly different requirements than native GPS-based applications. Each platform has its advantages and disadvantages and it all comes down to your requirements, budget, timeframes and skill sets:

  • Ability to re-use existing JavaScript and HTML5 skills to build a high-accuracy mobile application.
  • Don’t have access to native platform developers or skillsets on Android, iPhone and/or Windows Phone.
  • Need a cross-platform stand-alone web app, or a web app that has been repurposed to work with PhoneGap or Titanium.
  • Quickly locate the user/consumer within a reasonable expectation of accuracy.
  • Typically it is a non-commercial, consumer grade application that does not have extremely high accuracy requirements (e.g. < 1 meter).

How fast can I get an initial location result? The answer is very fast, potentially within a few seconds, given the following scenarios:

  • If there was a cached GPS or Network location stored on the phone. The GPS location is, of course, from the GPS chipset. The Network location comes from your wireless carrier and is dependent on your phone and their capabilities.
  • How the timeout and maximumAge properties are set. If you set timeout = 0 and maximumAge = Infinity it will force the application to grab any cached location, if one is available. Other settings may result in delays.
  • If the phone or tablet has decent internet connectivity and Wifi enabled.
  • If the device is in an urban area with many wifi nodes broadcasting their SSIDs nearby.
  • The device has a clear and uninterrupted view of the sky. GPS’s listen for a very weak signal from multiple satellites. These signals can be partially or completely blocked by buildings, thick foliage, vehicle roofs, etc.

 How accurate is the initial location result? Hah, you might have guessed I’d say that it depends.  When you first kick off a geolocation request, accuracy does depend on a number of different factors that are mentioned above. And it’s safe to say that, in the vast majority of cases, the first location is not the most accurate and typically not the most dependable. If you want the fastest, most accurate location possible then you will most likely need to either do multiple snapshots, or use watchLocation until your desired level of accuracy is met. It’s important to note because I’ve been asked about this many times, you cannot expect the GPS, itself, to have enough time to lock onto a satellite and deliver a fast, accurate initial location. It may take dozens of seconds or even minutes. Yep, it’s true. Factors that affect initial location accuracy include:

  • Cached locations – how recently the user accessed location functionality. For example, applications like Facebook typically grab a location when you open the app. So frequent users of social media are more likely to have a fresh, cached location that non-social media users. If you are targeting business travelers, the cached location might the last city before they got on a plane. Or, it could be your home neighborhood and not where you work or go to games.
  • Wifi turned “on”. If the Wifi is turned on then the device can access the location service and there is a much greater chance that the initial result is fairly accurate. If you didn’t have a chance to read Part 1, when the Wifi is on your browser gathers local Wifi node information from your Wifi card, and it can use that information in a location service provider request over the internet to try and triangulate your position. Typically this means your initial location can be within a block or two of the actual position. Also, it is possible if Wifi is turned on that you can get a significantly more accurate initial location than if you were using GPS by itself with no Wifi or internet.
  • Internet connectivity strength. If you have a poor internet connection and no Wifi, then the browser’s requests to the location service can be delayed, blocked or even interrupted.
  • No VPN. Take note commercial application developers: as mentioned in Part 1, if VPN software is in use it can wildly affect accuracy and even place you in another State (or Country).

Can I use HTML5 Geolocation for mobile tracking? Yes, with caveats. Typically HTML5 tracking applications are built inside a native wrapper framework such as PhoneGap or Titanium. There are several immediate problems with stand-alone, browser-only HTML5 tracking applications. First, there is no built-in functionality to keep the screen from going to sleep. Second, when the screen goes to sleep the HTML5 Geolocation functionality also goes to sleep. Native-based tracking applications can work around these limitations and listen passively in the background when they are minimized. Third, you have little control over the GPS settings to help management battery consumption.

Can I use HTML5 Geolocation offline? Yes! If there is no cellular connection or Wifi available, then HTML5 Geolocation can still access cached locations and real-time GPS information. This is vastly different from what was discussed in Part 1 as related to applications targeted at laptops, desktops and tablets that may or may not have GPS. If a device does not have a built-in or externally available GPS then your offline application will not work.

Handling abnormal location results. Your application will occasionally encounter widely inaccurate results and you need to handle these gracefully for the best user experience possible. My recommendation is to check the timestamps and distance traveled between the current geolocation object and the previous one. If the distance or speed seems excessive then you’ll need to reject the result. In the reference section below is a link to more information on calculating the distance between two points containing latitude and longitude. As an example, see the attached screenshot with the spurious results indicated by red circles. Also note in the screenshot the accuracy level was 3 meters, so it’s important to understand that even at high accuracy levels you still need to very that each location meets your minimum requirements. This way your results will always look polished and professional to the end user.

Spurious results

What are some of the downsides of using HTML5 Geolocation versus native? The bottom line is that for simple location gathering and basic tracking HTML5 Geolocation is just fine. This should meet the requirements for most consumer applications. For anything more complex than that you should consider looking at going native.

  • It may not work on older phones and older browsers (depending on your definition of old). See below in the references section for a link to a fallback library to handle these situations.
  • HMTL5 Geolocation offers significantly less control over GPS settings. This can have an unacceptable impact on more complex applications.  Because of this, I also suggest that HTML5 Geolocation is not suitable for long-running tracking applications.
  • Battery life management. This is a direct result of bullet #2. It’s more challenging to manage battery life with HTML5 Geolocatoin if your requirements call for continuous use of the GPS.  Your control is very limited with respect to these two properties: timeout and maximumAge.
  • Cannot use it when the application is minimized. If your requirements calls for the ability to passively receive locations while in a minimized state then, as mentioned earlier, you will have to go native.
  • Very little control over how often you want location updates. You’ll need to do a bunch of custom coding to emulate what is already built into native application APIs. For example, the native Android API offers very detailed control over what type of geolocation data you can get access to, how you can access it and how often. Read more on that topic in my post on How Accurate is Android GPS Part 1 – Understanding Location Data and also take a look at Android’s LocationManager Class.

References

W3C Geolocation API Specification 

HTML5 Geolocation Test Tool

Mozilla – Using Geolocation

Calculating distance between two points.

Geolocation fallback library for older browsers

Tags: , , , , , , , ,
Posted in Browsers, HTML5, Mobile | 19 Comments »

Accessing HTML5 Geolocation via ActionScript

Read on to learn how to access the HTML5 Geolocation API using ActionScript in a web app. Using the patterns below you can get access to a visitor’s approximate location in applications that run in a desktop or laptop browser. Mobile ActionScript/Flex/AIR apps have convenient, built-in access to location via the flash.sensors.Geolocation Class. However, with a web app you have to cobble together your own code using ExternalInterface.

The key to all this is using ExternalInterface’s addCallback().  This method lets you access ActionScript from JavaScript code in the wrapper HTML file, which if you didn’t know is the .html file that is used to launch Flash Player.

There are two steps to take that make it work:

Step 1. In addCallback() set the first parameter to the name of the function you will invoke in JavaScript to send data to your ActionScript method. Set the second parameter to the name of the actual ActionScript method. ActionScript will then recognize when the method specified in the second parameter is called. Essentially this sets up a listener in ActionScript.

Step 2. Set the call() method so that it invokes a public JavaScript function. When it’s done running, then you fire off the JavaScript function specified in the first parameter of addCallback().

If that doesn’t make any sense, check out the code below to see how it all fits together. Note, you can either hard code your JavaScript in the wrapper HTML file, or you can do what I do below and inject it into the DOM at runtime using the document.insertScript pattern so you know it’s always there.

public function findLocation():void
{
	if (!Geolocation.isSupported)
	{
		const  VERIFY_GEOLOCATION:String =
			"document.insertScript = function(){" +
				"verify_geolocation = function(){"+
					"var geoEnabled = false;" +
					"if(navigator && navigator.geolocation)" +
					"{" +
					"    return geoEnabled = true;" +
					"}" +
					"else{" +
					"    return geoEnabled = false;" +
					"}"+
				"}"+
			"}";

		const  GET_GEOLOCATION:String =
			"document.insertScript = function(){" +
				"get_geolocation = function(){"+
					"var mySWF = document.getElementById('YourApplicationName');"+
					"navigator.geolocation.getCurrentPosition(function(position){"+
					"     mySWF.sendGeolocationToActionScript(position);"+
					"});"+
				"}"+
			"}";

		if(ExternalInterface.available)
		{
			//load the script into DOM
			ExternalInterface.call(VERIFY_GEOLOCATION);

			//call the JS function
			var geoEnabled:Boolean = ExternalInterface.call("verify_geolocation");

			if(geoEnabled == true){
				//Load the script into DOM
				ExternalInterface.call(GET_GEOLOCATION);

				//Step 1: set the ActionScript callback
				ExternalInterface.addCallback("sendGeolocationToActionScript",geolocationResultHandler);

				//Step 2: call the JS Function
				ExternalInterface.call("get_geolocation");
			}
		}
	}
}

//Access this Handler from JavaScript
public function geolocationResultHandler(obj:Object):void
{
	//Access the HTML5 Geolocation object properties just like you would in JavaScript
	Alert.show("Latitude: " + obj.coords.latitude + ", "Longitude: " + obj.coords.longitude );
}

Test Notes:

I compiled this code using FlashBuilder 4.6 using Apache Flex 4.6. The functionality was tested on Internet Explorer 9, Chrome 21 and Firefox 14.

References:

Adobe ActionScript Reference – ExternalInterface
Adobe Help – Accessing Flex from JavaScript

Tags: , , ,
Posted in ActionScript, FlashBuilder, HTML5 | No Comments »

Want a fast and fun learning experience on adding location to your web apps? I’ll be sharing practical tips on how to shave days or weeks off your learning curve. The session will cover the HTML5 Geolocation API, its benefits, how it works and what doesn’t work using real-world examples covering both desktop and mobile. If you are planning on attending OSCON 2012 stop by my session and say “hi”. My session is Location, Location, Location – Mastering HTML5 Geolocation, 1:40pm Thursday, July 19th in Portland 251.

 

Tags: , , , , , , , , ,
Posted in Conferences, HTML5 | No Comments »

Presenting at LinuxFestNW 2012 on HTML5 Geolocation

This weekend I’ll be presenting at LinuxFestNW 2012. We (Esri) will also have a booth there, so if you are in the area of Bellingham, WA swing on by.

My topic will be HTML5 Geolocation and I’ll be talking about building applications using the HTML5 Geolocation API from A to Z. I’m going to start out looking at basic coding patterns, then we’ll discuss accuracy across different browsers, look at many common gotchas, and I’ll be giving tips on how to effectively implement it with local and remote database. If you attend, come prepared to get a full dose of HTML5 goodness.

Here’s the link to the prezi: http://prezi.com/kawyhcqxjdip/html5-geolocation-api-location-location-location/

Tags: , , , , , , , , ,
Posted in Conferences, JavaScript | No Comments »