WVLocation provides JavaScript APIs for geographic location in WindVane HTML5 apps and miniapps. Use WVLocation.getLocation to retrieve the device's current position and WVLocation.searchLocation to resolve an address to coordinates.
WVLocation.getLocation
Retrieves the device's current geographic location.
iOS requires the following configuration before calling this API:
iOS 8–10: add
NSLocationWhenInUseUsageDescriptionandNSLocationAlwaysUsageDescriptiontoInfo.plistto trigger the location permission prompt.iOS 11 and later: add
NSLocationAlwaysAndWhenInUseUsageDescriptionandNSLocationWhenInUseUsageDescriptiontoInfo.plist.All iOS versions: register
EMASUserInfoServicebefore calling this API.
Input parameters
|
Parameter |
Type |
Required |
Description |
|
|
|
No |
Specifies whether to request a high-accuracy location. Valid values: |
|
|
|
No |
Specifies whether to include a reverse-geocoded address (such as city and province) in the response. Setting this to |
Success response
The callback receives an object with the following fields.
coords — coordinates object (object)
|
Field |
Type |
Description |
|
|
|
Longitude of the location. |
|
|
|
Latitude of the location. |
|
|
|
Accuracy radius, in meters. |
address — address object (object, returned only when address: true)
|
Field |
Type |
Description |
|
|
|
City name. |
|
|
|
Province name. |
|
|
|
District name. |
|
|
|
Road name. |
|
|
|
Full formatted address. |
|
|
|
City code. Available only on Taobao Android apps. Non-Taobao Android apps and Google-based responses do not include this field. |
Location accuracy and the underlying location provider affect the address fields returned. Some fields may be missing or inaccurate. Add error handling for incomplete or unexpected address data in your HTML5 apps or miniapps.
Example
var params = {
// Whether to request a high-accuracy location.
enableHighAccuracy: true,
// Whether to include the reverse-geocoded address.
address: true
};
window.WindVane.call('WVLocation', 'getLocation', params, function(e) {
alert('success:' + JSON.stringify(e));
}, function(e) {
alert('failure:' + JSON.stringify(e));
});
Example success response:
{
"coords": {
"longitude": "120.126293",
"latitude": "30.274653",
"accuracy": "200"
},
"address": {
"city": "Hangzhou",
"province": "Zhejiang",
"area": "Xihu District",
"road": "Xueyuan Road",
"addressLine": "No.77 Xueyuan Road, Xihu District, Hangzhou",
"cityCode": "0571"
}
}
WVLocation.searchLocation
This API is available only in WindVane iOS.
Resolves an address string to geographic coordinates (latitude and longitude).
Input parameters
|
Parameter |
Type |
Required |
Description |
|
|
|
Yes |
The address to resolve. |
Success response
The callback receives an object with the following fields.
|
Field |
Type |
Description |
|
|
|
Longitude of the resolved address. |
|
|
|
Latitude of the resolved address. |
Example
var params = {
// The address to resolve.
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));
});