Location

更新时间:
复制 MD 格式

This topic describes the JavaScript APIs (JSAPIs) for the `WVLocation` class. These APIs allow you to search for and retrieve geographic locations in H5 applications and miniapps created using cross-platform DevOps.

WVLocation.getLocation

Retrieves the current geographic location.

Note
  • In iOS 8 and later, Apple changed the location permission model for applications. To display the location permission request prompt, you must add the NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription keywords to the Info.plist file.

  • In iOS 11 and later, you must add both the NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keywords to the Info.plist file to display the location permission request prompt.

Input parameters

  • [boolean] enableHighAccuracy: Optional. Specifies whether to retrieve a high-accuracy location. Valid values: true and false. The default value is false.

  • [boolean] address: Optional. Specifies whether to retrieve the address description, such as Hangzhou, China. Valid values: true and false. The default value is false. Setting this parameter to `false` results in a faster response for the latitude and longitude.

Callback parameters

The callback parameters are passed to the `success` callback method if the operation is successful, or to the `failure` callback method if the operation fails.

  • [object] coords: Latitude and longitude information.

    • [string] longitude: The longitude.

    • [string] latitude: The latitude.

    • [string] accuracy: The horizontal accuracy.

  • [object] address: Address information.

    • [string] city: The city.

    • [string] province: The province.

    • [string] area: The district.

    • [string] road: The road.

    • [string] addressLine: The detailed address.

    • [string]cityCode: The city code. This field is unavailable for non-Taobao clients on the Android platform because the data returned by Google does not include this field.

Important

The address information may be incomplete or inaccurate due to the precision of the location service or the APIs used. You must handle data exceptions in your H5 application.

var params = {
        // Specifies whether to get a high-accuracy location
        enableHighAccuracy: true,
        // Specifies whether to get the address description
        address: true
};
window.WindVane.call('WVLocation', 'getLocation', params, function(e) {
        alert('success:' + JSON.stringify(e));
}, function(e) {
        alert('failure:' + JSON.stringify(e));
});

WVLocation.searchLocation

Note

This API is available only for WindVane for iOS.

Searches for the latitude and longitude of a given address.

Input parameter

  • [string] addrs: The address to search for.

Callback parameters

The callback parameters are passed to the `success` callback method if the operation is successful, or to the `failure` callback method if the operation fails.

  • [string] longitude: The longitude.

  • [string] latitude: The latitude.

var params = {
        // The address to search for
        addrs: ' 960 West xxxx Road'};
window.WindVane.call('WVLocation', 'searchLocation', params, function(e) {
        alert('success:' + JSON.stringify(e));
}, function(e) {
        alert('failure:' + JSON.stringify(e));
});