HTML and CSS Reference
Cell Tower Triangulation - This uses the same principle as Wi-Fi positioning except it
uses cellular telephone towers. It is not as accurate, however, because a cell tower has a
much larger range. Since all cell phones will have the ability to communicate with cell
towers, this technology has a broad application.
IP Block - Every device that connects to the internet will have an IP address, which is
usually provided by the ISP. Each ISP will have a block of IP addresses that it can use,
which are typically assigned by geographical location. So the IP address with which you
connect to the internet can provide a general location, usually a metropolitan area. There
are several factors, however, that can yield incorrect results, such as NATted addresses.
Each of these technologies has different hardware requirements and provide varying levels of accuracy.
With the Geolocation specification, you can easily request the current location from the browser and let it
determine the best way to supply that based on the current hardware and access to external sources including
satellites, cell towers, and W-Fi networks.
Using Geolocation Data
Most people think of geolocation as a device that provides turn-by-turn directions but that is only one application
of this technology. Of course this requires very precise location that can only be obtained through GPS. However,
even when the current location is far less accurate, your web site can still make valuable use of this information.
Even if the location is determined only by the IP address, this will usually be sufficient to set the default language,
for example. You may need to allow the end user to override this but most of your audience will see the initial
page in their native language.
When retrieving the current location, the geolocation service also returns the estimated accuracy. Your
application should use this to determine the features that will be provided. Suppose, for example, that you're
creating a web page for the U.S. Postal Service that shows where the nearest post offices are. If the current
location is known with very high accuracy, the web page can show a map and indicate the current location as
well as the nearby post offices. In addition, it could provide the estimated driving time to each.
However, if the location is known with lesser accuracy, the page could display a map that shows where the
post offices are in that general area. Presumably, the user will know where they are and can use this information
to determine the best location to use. However, if the accuracy is very poor, the page should prompt for a zip code
and then display the nearest post offices based on the user input. So, depending on the accuracy, the application
can gracefully degrade the functionality.
Using the Geolocation API
To demonstrate how to use the Geolocation API, you'll create a simple web page that calls the API to determine
your current location. Initially, this data will be displayed on the web page as text. Later you'll display this
location on a map.
Creating the Visual Studio Project
You'll start by creating a Visual Studio project using the same Basic MVC template that you have used
in previous chapters.