HTML and CSS Reference
In-Depth Information
• E-commerce web sites can use the location information to suggest shipping costs to
the user.
• Real-estate applications can customize search results based on the user's location.
• Museums, theaters, gathering halls, and such establishments can calculate the
approximate travel time from a user's location to the venue.
Geolocation and User Privacy
The user's geographical location is considered a private piece of information, and the user needs to
provide explicit approval before the browser can send the data to the server for further processing.
Whenever you access a web page that uses the Geolocation API, the browser notifies you that you're about
to share your location information with the page and prompts you to confirm this action. For example,
Figure 12-1 shows how Firefox, Chrome, and IE9 prompt the user to confirm the use of Geolocation API.
Figure 12-1. Browsers asking permission to send location information to the server
As you can see, unless the user explicitly grants permission to transmit their location on the Web, the
web application can't use the Geolocation API. The user can revoke this permission at any time using their
browser options.
In certain cases, you may also want to send the user's location information to a third-party system. As
a good practice, it's better to keep the user informed about such sharing.
Using the Geolocation API to obtain User's Location
Now that you have a basic understanding of what the Geolocation API does, let's develop a simple Web
Forms-based application that illustrates how you can use the getCurrentPosition() method to find the
user's location. The application's main web form is shown in Figure 12-2.
Search WWH ::

Custom Search