Lesson 38

Location API

Developing web applications for mobile phones can simply mean utilizing the techniques and technologies associated with responsive web design and ensuring that the user receives the best possible experience regardless of the screen resolution.

It can also open up a whole world of possibilities, however, by taking advantage of the features and services that are unique to mobile devices. For instance, mobile devices typically provide a variety of services that can be used in applications:

  • The ability to detect the location of the device
  • The ability to detect motion—for instance, the user moving the device side to side
  • The ability to know which direction the device is facing
  • The ability to take photos and videos
  • The ability to connect to periphery devices using wireless technologies such as Bluetooth
  • The ability to receive and generate notifications

Unfortunately it is not currently possible to interact with most of these services via JavaScript because they are only made available with native APIs, and these vary across platforms.

One API that is available in JavaScript, however, is the Geolocation API. This lesson looks at how you can take advantage of this API to create a web application that tracks a user's motion.

The Geolocation API is available in JavaScript via the navigator.geolocation object. This API is available in all the most common browsers, regardless of the device the browser is running on.

Despite the fact that the Geolocation API is ...

Get HTML5, JavaScript, and jQuery 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.