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.
From
iOS 8to iOS 10, the request for location permissions is displayed only afterNSLocationWhenInUseUsageDescriptionandNSLocationAlwaysUsageDescriptionare added toInfo.plist.In
iOS 11and later, the request for location permissions is displayed only afterNSLocationAlwaysAndWhenInUseUsageDescriptionandNSLocationWhenInUseUsageDescriptionare added toInfo.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:trueandfalse. Default value:false.[
boolean]address: (optional) specifies whether to obtain the address, such as China (Hangzhou). Valid values:trueandfalse. 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.
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
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));
});