check location settings
检查定位权限
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_LOCATION_SETTINGS, (result) => { if (result.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('checkLocationSettings...', 'success'); } else { cc.log('checkLocationSettings...', 'fail:', result.errMsg); } }); huawei.hms.location.locationService.checkLocationSettings();
Updates the location under processing
刷新当前正在处理的位置
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_FLUSH_LOCATIONS, (result) => { if (result.code === huawei.hms.location.LocationService.StatusCode.success) { console.log('flushLocations success,data is ', result.toString()); } else { console.log('flushLocations fail ,reason ', result.errMsg); } }); huawei.hms.location.locationService.flushLocations();
get last location
获取最后位置
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_LAST_LOCATION, (location) => { if (location.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('getLastLocation...', 'success', lon:' + location.longitude + ",lat:" + location.latitude); } else { cc.log('getLastLocation...', 'fail:', location.errMsg); } }); huawei.hms.location.locationService.getLastLocation();
Obtains the available location of the last request, including the detailed address information. If a location is unavailable, null will be returned.
null
返回最后一次请求的可用位置,包括详细地址信息。如果某个位置不可用,则返回 null。
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_GET_HWLOCATION, (result) => { if (result.code === huawei.hms.location.LocationService.StatusCode.success) { console.log('getLastLocationWithAddress success,data is ', JSON.stringify(result)); } else { console.log('getLastLocationWithAddress fail ,reason ', result.errMsg); } }); huawei.hms.location.locationService.getLastLocationWithAddress();
remove event listener
取消事件的监听
huawei.hms.location.locationActivityService.off(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_ACTIVITY_UPDATES, (result) => { //TODO }
event name
callback function
target node
event listener
持续监听事件
huawei.hms.location.locationActivityService.on(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_ACTIVITY_UPDATES, (result) => { //TODO }
event callback
event listener for once
监听一次事件
huawei.hms.location.locationActivityService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_DELETE_ACTIVITY_IDENTIFICATION_UPDATES, (result) => { //TODO }
remove location updates
取消持续监听
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_REMOVE_LOCATION_UPDATE, (result) => { if (result.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('removeLocationUpdates...', 'success'); } else { cc.log('removeLocationUpdates...', 'fail:', result.errMsg); } }); huawei.hms.location.locationService.removeLocationUpdates();
request location permission
请求定位权限
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_LOCATION_PERMISSION, (result) => { if (result.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('checkLocationSettings...', 'success'); } else { cc.log('checkLocationSettings...', failed, errMsg = ', result.errMsg); } }); huawei.hms.location.locationService.requestLocationPermission();
request location updates
请求持续监听位置信息
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_REQUEST_LOCATION_UPDATE, (result) => { if (result.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('requestLocationUpdates...', 'success'); } else { cc.log('requestLocationUpdates...', 'fail:', result.errMsg); } }); huawei.hms.location.locationService.requestLocationUpdates();
Requests location updates. This is an extended location service API that supports high-precision location and is compatible with common location APIs.
扩展的位置信息服务接口,当前支持高精度定位,并兼容普通定位接口
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_REQUEST_LOCATION_UPDATE, (result) => { if (result.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('requestLocationUpdatesEx...', 'success'); } else { cc.log('requestLocationUpdatesEx...', 'fail:', result.errMsg); } }); huawei.hms.location.locationService.requestLocationUpdatesEx();
set location interval, unit: ms
设置位置信息返回的事件间隔,单位:毫秒
huawei.hms.location.locationService.setLocationInterval(10000);
location callback interval
set location priority, value: com.huawei.hms.location.LocationRequest
设置优先级,如果请求GPS位置,则值为100;如请求网络位置,则值为102或104;如不需要主动请求位置,仅需被动接收位置,则值为105。如果请求高精度位置信息,则值为200。
huawei.hms.location.locationService.setLocationPriority(100);
set mock location
设置虚拟定位的信息
longitude
latitude
set mock mode
设置虚拟定位的开关
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_MOCK_MODE, (result) => { if (location.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('setMockMode...', 'success'); } else { cc.log('setMockMode...', 'fail:', result.errMsg); } }); huawei.hms.location.locationService.setMockMode(true);
true is open ,false is close
remove all event listener for the node
取消某个节点所有的事件监听
huawei.hms.location.locationService.targetOff(this);
Generated using TypeDoc
check location settings
检查定位权限
huawei.hms.location.locationService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_LOCATION_SETTINGS, (result) => { if (result.code === huawei.hms.location.LocationActivityService.StatusCode.success) { cc.log('checkLocationSettings...', 'success'); } else { cc.log('checkLocationSettings...', 'fail:', result.errMsg); } }); huawei.hms.location.locationService.checkLocationSettings();