All Products
Search
Document Center

SuperApp:Geographic location

Last Updated:Oct 31, 2024

This topic describes the JavaScript APIs of WVLocation. You can refer to this topic when you create HTML5 apps or Miniapps. You can use the JavaScript APIs of WVLocation to search for or obtain a geographic location.

WVLocation.getLocation

Obtains a geographic location.

Note
  • From iOS 8 to iOS 10, the request for location permissions is displayed only after NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription are added to Info.plist.

  • In iOS 11 and later, the request for location permissions is displayed only after NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription are added to Info.plist.

  • iOS needs to register the EMASUserInfoService to invoke this API

Input parameters

  • [string]enableHighAccuracy: (optional) specifies whether to obtain a high-precision location. Valid values: true and false. Default value: false.

  • [boolean]address: (optional) specifies whether to obtain the address, such as China (Hangzhou). Valid values: true and false. The response time can be shortened by setting this parameter to false. Default value: false.

Callback parameters

Callback parameters are passed by using the callback method. If the geographic location is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.

  • [object]coords: the coordinates of the location.

    • [string]longitude: the longitude.

    • [string]latitude: the latitude.

    • [string]accuracy: the precision.

  • [object]address: the address.

    • [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. If your Android app is not Taobao, you cannot obtain the city code because the data returned by Google does not contain this field.

Important

The location precision and location interface may affect the returned address. The address may not contain some fields, or the address may be inaccurate. Therefore, we recommend that you configure proper error handling for abnormal data in your HTML5 apps or MiniApps.

var params = {
        // Specify whether to obtain a high-precision location.
        enableHighAccuracy: true,
        // Specify whether to obtain the address.
        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 in WindVane iOS.

Searches for the specified address and obtains the latitude and longitude.

Input parameters

  • [string]addrs: the address that you want to search for.

Callback parameters

Callback parameters are passed by using the callback method. If the geographic location is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.

  • [string]longitude: the longitude.

  • [string]latitude: the latitude.

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