Posts in current category
May 03, 2021 13:05 HTML5
HTML5 Geolocation (geolocation) is used to locate a user's location.
Geolocation requests a location information, and with the user's consent, the browser returns a location information that contains longhes and dimensions!
The HTML5 Geolocation API is used to obtain the user's geographic location.
Because this feature may violate a user's privacy, user location information is not available unless the user consents.
Internet Explorer 9 Plus, Firefox, Chrome, Safari and Opera support Geolocation.
Note: Geolocation is more accurate for devices with GPS, such as the iPhone.
Use the getCurrentPosition() method to get the user's location.
The following example is a simple geolocation instance that returns the longitude and latitude of the user's location:
The example above is a very basic geolocation script that does not contain error handling.
Tip: Geolocation location sources can include GPS, IP address, RFID, WIFI and Bluetooth MAC address, as well as GSM/CDMS ID, and so on.
The second parameter of the getCurrentPosition() method is used to handle errors. It specifies the function that runs when the acquisition of the user's location fails:
To display results in a map, you need access to a map service that uses longitude and latitude, such as Google Maps or Baidu Maps:
In the example above, we use the returned longitude and latitude data to display the location in Google Maps (using still images).
Google Maps script
The links above show you how to use scripts to display interactive maps with tag, zoom, and drag options.
This page shows how to display a user's location on a map. However, geolocation is also useful for information about a given location.
If T succeeds, the getCurrentPosition() method returns the object. T he latitude, longitude, and accuracy properties are always returned. If available, other properties below are returned.
WatchPosition() - Returns the user's current location and continues to return the updated location (like GPS on the car) when the user moves.
clearWatch() - Stop watchPosition() method
The following example shows the watchPosition() method. Y ou need an accurate GPS device to test this example (e.g. iPhone):
We'll cover geolocation in HTML5, and we'll learn about HTML5 video in the next section!