diff --git a/en/application-dev/device/device-location-geocoding.md b/en/application-dev/device/device-location-geocoding.md index e0080e3e87ddfc28779c7023c75d464e23af78da..f95df63eebe64eedb6063ae193f4b141bfd946c6 100644 --- a/en/application-dev/device/device-location-geocoding.md +++ b/en/application-dev/device/device-location-geocoding.md @@ -36,13 +36,29 @@ The following table describes APIs available for mutual conversion between coord import geolocation from '@ohos.geolocation'; ``` -2. Obtain the conversion result. +2. Query whether geocoder service is available. + - Call **isGeoServiceAvailable** to query whether the geocoder service is available. If the service is available, continue with step 3. + ``` + geolocation.isGeoServiceAvailable((err, data) => { + if (err) { + console.log('isGeoServiceAvailable err: ' + JSON.stringify(err)); + } else { + console.log('isGeoServiceAvailable data: ' + JSON.stringify(data)); + } + }); + ``` + +3. Obtain the conversion result. - Call **getAddressesFromLocation** to convert coordinates into geographical location information. ``` var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; - geolocation.getAddressesFromLocation(reverseGeocodeRequest, (data) => { - console.log('getAddressesFromLocation: ' + JSON.stringify(data)); + geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { + if (err) { + console.log('getAddressesFromLocation err: ' + JSON.stringify(err)); + } else { + console.log('getAddressesFromLocation data: ' + JSON.stringify(data)); + } }); ``` @@ -51,8 +67,12 @@ The following table describes APIs available for mutual conversion between coord ``` var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; - geolocation.getAddressesFromLocationName(geocodeRequest, (data) => { - console.log('getAddressesFromLocationName: ' + JSON.stringify(data)); + geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { + if (err) { + console.log('getAddressesFromLocationName err: ' + JSON.stringify(err)); + } else { + console.log('getAddressesFromLocationName data: ' + JSON.stringify(data)); + } }); ``` diff --git a/en/application-dev/device/device-location-info.md b/en/application-dev/device/device-location-info.md index 84f189d7f247bd9516204c7dd0d76aafb6438dbb..dce40ff38546fe1b86a60bf670cb18adf9e15968 100644 --- a/en/application-dev/device/device-location-info.md +++ b/en/application-dev/device/device-location-info.md @@ -123,7 +123,7 @@ To learn more about the APIs for obtaining device location information, see [Geo The following example instantiates the **RequestParam** object for navigation: ``` - var requestInfo = {'scenario': 0x301, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; + var requestInfo = {'scenario': geolocation.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; ``` **Method 2:** @@ -152,7 +152,7 @@ To learn more about the APIs for obtaining device location information, see [Geo The following example instantiates the **RequestParam** object for the location accuracy priority policy: ``` - var requestInfo = {'priority': 0x201, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; + var requestInfo = {'priority': geolocation.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; ``` 4. Instantiate the **Callback** object for the system to report location results. @@ -179,8 +179,12 @@ To learn more about the APIs for obtaining device location information, see [Geo If your application does not need the real-time device location, it can use the last known device location cached in the system instead. ``` - geolocation.getLastLocation((data) => { - console.log('getLastLocation: data: ' + JSON.stringify(data)); + geolocation.getLastLocation((err, data) => { + if (err) { + console.log('getLastLocation: err: ' + JSON.stringify(err)); + } else { + console.log('getLastLocation: data: ' + JSON.stringify(data)); + } }); ``` diff --git a/zh-cn/application-dev/device/device-location-geocoding.md b/zh-cn/application-dev/device/device-location-geocoding.md index d15b8df3418540ef13cedde828173a1948d9e8fc..8e87eab224a108cd6b620b3bda272c39abda82e8 100644 --- a/zh-cn/application-dev/device/device-location-geocoding.md +++ b/zh-cn/application-dev/device/device-location-geocoding.md @@ -39,13 +39,30 @@ import geolocation from '@ohos.geolocation'; ``` -2. 获取转化结果。 +2. 查询geoCoder服务是否可用。 + - 调用isGeoServiceAvailable查询geoCoder服务是否可用,如果服务可用再继续进行步骤3。 + + ``` + geolocation.isGeoServiceAvailable((err, data) => { + if (err) { + console.log('isGeoServiceAvailable err: ' + JSON.stringify(err)); + } else { + console.log('isGeoServiceAvailable data: ' + JSON.stringify(data)); + } + }); + ``` + +3. 获取转化结果。 - 调用getAddressesFromLocation,坐标转化地理位置信息。 ``` var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; - geolocation.getAddressesFromLocation(reverseGeocodeRequest, (data) => { - console.log('getAddressesFromLocation: ' + JSON.stringify(data)); + geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { + if (err) { + console.log('getAddressesFromLocation err: ' + JSON.stringify(err)); + } else { + console.log('getAddressesFromLocation data: ' + JSON.stringify(data)); + } }); ``` @@ -54,8 +71,12 @@ ``` var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; - geolocation.getAddressesFromLocationName(geocodeRequest, (data) => { - console.log('getAddressesFromLocationName: ' + JSON.stringify(data)); + geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { + if (err) { + console.log('getAddressesFromLocationName err: ' + JSON.stringify(err)); + } else { + console.log('getAddressesFromLocationName data: ' + JSON.stringify(data)); + } }); ``` diff --git a/zh-cn/application-dev/device/device-location-info.md b/zh-cn/application-dev/device/device-location-info.md index dd33246667312f12f97424d63da27b03cf24682a..9aa69b81798ff67508e57c70ca22374e6da16907 100644 --- a/zh-cn/application-dev/device/device-location-info.md +++ b/zh-cn/application-dev/device/device-location-info.md @@ -123,7 +123,7 @@ 以导航场景为例,实例化方式如下: ``` - var requestInfo = {'scenario': 0x301, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; + var requestInfo = {'scenario': geolocation.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; ``` **方式二:** @@ -152,7 +152,7 @@ 以定位精度优先策略为例,实例化方式如下: ``` - var requestInfo = {'priority': 0x201, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; + var requestInfo = {'priority': geolocation.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; ``` 4. 实例化Callback对象,用于向系统提供位置上报的途径。 @@ -179,8 +179,12 @@ 如果应用使用场景不需要实时的设备位置,可以获取系统缓存的最近一次历史定位结果。 ``` - geolocation.getLastLocation((data) => { - console.log('getLastLocation: data: ' + JSON.stringify(data)); + geolocation.getLastLocation((err, data) => { + if (err) { + console.log('getLastLocation: err: ' + JSON.stringify(err)); + } else { + console.log('getLastLocation: data: ' + JSON.stringify(data)); + } }); ```