Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
143023864X_HT5.pdf
Скачиваний:
8
Добавлен:
21.02.2016
Размер:
7.98 Mб
Скачать

CHAPTER 5 USING THE GEOLOCATION API

Privacy

The Geolocationspecification mandates that a mechanism is provided to protect the user's privacy. Furthermore, location information should not be made available unless the application’s users grant their express permission.

This makes sense and addresses the “big brother” concerns users often raise about Geolocation applications. However, as you can see from some of the possible use cases for HTML 5 Geolocation applications, there is usually an incentive for the user to share this information. For example, users might be OK with sharing their location if this could let them know about a rare 50% discount on a pair of running shoes that are ready to be picked up in a store located just a few blocks away from where they happen to be drinking coffee. Let’s take a closer look at the browser and device privacy architecture shown in Figure 5-1.

Figure 5-1. Geolocation browser and device privacy architecture

The following steps are shown in the diagram:

1.A user navigates to a location-aware application in the browser.

2.The application web page loads and requests coordinates from the browser by making a Geolocation function call. The browser intercepts this and requests user permission. Let's assume, in this case, that the permission is granted.

3.The browser retrieves coordinate information from the device it is running on. For example, a combination of IP address, Wi-Fi, and possibly GPS coordinates. This is an internal function of the browser.

4.The browser sends these coordinates to a trusted external location service, which returns location coordinates that can now be sent back to the host of the Geolocation application.

112

CHAPTER 5 USING THE GEOLOCATION API

Important The application does not have direct access to the device; it can only query the browser to access the device on its behalf.

Triggering the Privacy Protection Mechanism

When you access a web page that uses the Geolocation API, the privacy protection mechanism should kick in. Figure 5-2 shows what this looks like in Firefox.

Figure 5-2. The notification bar is triggered in Firefox when the Geolocation API is used.

The mechanism is triggered when the Geolocation code is executed. Simply adding Geolocation code that is not called anywhere (for example, in an onload method) does not do anything. If, however, the Geolocation code is executed, for example, in a call to navigator.geolocation.getCurrentPosition (explained in more detail later on), the user is prompted to share their location with the application. Figure 5-3 shows what happens on Safari, running on an iPhone.

Figure 5-3. The notification dialog box is triggered in Safari when the Geolocation API is used.

Apart from providing the necessary mechanism to request permission to share your location, some implementations (Firefox, for example) also allow you to remember the permission granted to the site for the next time you enter. This is similar to how you can remember passwords for certain sites in your browser.

Note if you've given permission to always give your location to a site in Firefox and later change your mind, you can easily revoke that permission by going back to the site and selecting Page Info from the Tools menu. Then change the setting for Share Location on the Permissions tab.

113