Obtain geographic location information and geographical location
In HTML5, A geolocation attribute is added to the window. navigator object. You can use the Geolocation API to access this attribute. The geolocation attribute of the window. navigator object has the following three methods.
Void getCurrentPosition (onSuccess, onError, options );
This method is used to obtain the current geographical location information of a user.
Navigator. geolocation. getCurrentPosition (
Function (position) {}, // when the user's geographical location is obtained successfully, call parameter 1.
Function (error) {}, // call parameter 2 when the user fails to obtain the location
{} // Optional attribute parameter 3
);
Parameter 1: This function has an object whose position parameter has the following attributes:
Latitude the latitude of the current geographic location
Longitude of the current geographic location of longpolling
Altitude current geographic location elevation
Accuracy of the latitude or Longitude obtained by accuracy (in meters)
AltitudeAccuracy
The Forward Direction of the heading device is indicated by the clockwise rotation angle toward the north.
Speed Device forward speed (in meters per second)
Time when timestamp obtains the geographic location
There are many ways to obtain positioning information, including GPS technology, which has the highest precision. In addition, you can also obtain location information through base stations and Wi-Fi hotspots.
For most developers, you only need to call the user's current location. In this case, you can use the getCurrentPosition () mentioned above. To monitor location changes, useWatchPosition ().