HTML5-Geolocation APIs

Source: Internet
Author: User

1. navigator. geolocation
The main object related to the geographical location in HTML5 is navigator. geolocation. It has some methods and attributes to detect the browser's support for the geographical location in html5.

2. getCurrentPosition, watchPosition, and clearWatch Methods
This is the two core methods of geolocation. The first method only obtains the geographic location information. The second method obtains the geographic location information at a certain interval. The parameters are the same, but the return values are different. The latter returns a watchId, passing the watchId as a parameter to the clearWatch method can terminate the request for geographic location information.
GetCurrentPosition is like:
Void getCurrentPosition (in PositionCallback successCallback,
In optional PositionErrorCallback errorCallback,
In optional PositionOptions options );
The first parameter is a function used to process the geographical location information received successfully. It usually receives a position object as a parameter and provides the geographical location information received.
The second parameter is optional and is also a function used for error handling. This function usually receives an error object as a parameter, and error contains error information.
The third parameter is also optional for further control of geographic location information. It is usually enclosed in curly brackets and usually has three values:
EnableHighAccuracy: used to control precision. Its effect may have side effects.
Timeout: specifies the time-out time for geographic location information requests, in milliseconds.
MaximumAge: used to specify the update frequency of geographic location information, in milliseconds.

An example is as follows:
Navigator. geolocation. getCurrentPosition (updateLocation, handleLocationError,
{Timeout: 10000 });

3. psition object
It is defined as follows:
Interface Position {
Readonly attribute Coordinates coords;
Readonly attribute DOMTimeStamp timestamp;
};
It has a sub-object coords and a property timestamp.
Coords: A Coordinates object. Its definition is as follows:
Interface Coordinates {
Readonly attribute double latitude; // dimension
Readonly attribute double longpolling; // longitude
Readonly attribute double? Altitude; // elevation (/m)
Readonly attribute double accuracy; // longitude and latitude accuracy (/m)
Readonly attribute double? AltitudeAccuracy; // elevation accuracy (/m)
Readonly attribute double? Heading; // direction of movement (/deg)
Readonly attribute double? Speed; // movement speed (/m/s)
};

Attributes With question marks are not implemented in many browsers and devices. Without these attributes, the value obtained by programming is null.
Latitude, longpolling, and accuracy attributes are used to provide the request dimension, longitude, and precision information. Latitude and longitude are represented by decimal digits, and the precision unit is meter.

Timestamp: timestamp.

4. error object
The error object has a code attribute used to specify the error type. It can be considered as an enumeration type and has four values: 0 (UNKNOWN_ERROR1, 1 (PERMISSION_DENIED), 2 (POSITION_UNAVAILABLE) and
3 (TIMEOUT ).
In addition, error has a message attribute to provide detailed error information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.