Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LocationService

Hierarchy

  • HMSBaseService
    • LocationService

Index

Constructors

constructor

Properties

Static StatusCode

StatusCode: LocationStatusCode = LocationStatusCode

Methods

checkLocationSettings

  • checkLocationSettings(): void
  • en

    check location settings

    zh

    检查定位权限

    example
    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();
    

    Returns void

flushLocations

  • flushLocations(): void
  • en

    Updates the location under processing

    zh

    刷新当前正在处理的位置

    example
    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();
    

    Returns void

getLastLocation

  • getLastLocation(): void
  • en

    get last location

    zh

    获取最后位置

    example
    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();
    

    Returns void

getLastLocationWithAddress

  • getLastLocationWithAddress(): void
  • en

    Obtains the available location of the last request, including the detailed address information. If a location is unavailable, null will be returned.

    zh

    返回最后一次请求的可用位置,包括详细地址信息。如果某个位置不可用,则返回 null

    example
    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();
    

    Returns void

off

  • off(event_name: string, callback: Function, target: any): void
  • en

    remove event listener

    zh

    取消事件的监听

    example
    huawei.hms.location.locationActivityService.off(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_ACTIVITY_UPDATES, (result) => {
        //TODO
    }
    

    Parameters

    • event_name: string

      event name

    • callback: Function

      callback function

    • target: any

      target node

    Returns void

on

  • on(event_name: string, cb: Function, node?: any): void
  • en

    event listener

    zh

    持续监听事件

    example
    huawei.hms.location.locationActivityService.on(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_ACTIVITY_UPDATES, (result) => {
        //TODO
    }
    

    Parameters

    • event_name: string

      event name

    • cb: Function

      event callback

    • Optional node: any

      target node

    Returns void

once

  • once(event_name: string, cb: Function, node?: any): void
  • en

    event listener for once

    zh

    监听一次事件

    example
    huawei.hms.location.locationActivityService.once(huawei.hms.location.HMS_LOCATION_EVENT_LISTENER_NAME.HMS_DELETE_ACTIVITY_IDENTIFICATION_UPDATES, (result) => {
        //TODO
    }
    

    Parameters

    • event_name: string

      event name

    • cb: Function

      event callback

    • Optional node: any

      target node

    Returns void

removeLocationUpdates

  • removeLocationUpdates(): void
  • en

    remove location updates

    zh

    取消持续监听

    example
    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();
    

    Returns void

requestLocationPermission

  • requestLocationPermission(): void
  • en

    request location permission

    zh

    请求定位权限

    example
    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();
    

    Returns void

requestLocationUpdates

  • requestLocationUpdates(): void
  • en

    request location updates

    zh

    请求持续监听位置信息

    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();
    

    Returns void

requestLocationUpdatesEx

  • requestLocationUpdatesEx(): void
  • en

    Requests location updates. This is an extended location service API that supports high-precision location and is compatible with common location APIs.

    zh

    扩展的位置信息服务接口,当前支持高精度定位,并兼容普通定位接口

    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();
    

    Returns void

setLocationInterval

  • setLocationInterval(interval: number): void
  • en

    set location interval, unit: ms

    zh

    设置位置信息返回的事件间隔,单位:毫秒

    example
    huawei.hms.location.locationService.setLocationInterval(10000);
    

    Parameters

    • interval: number

      location callback interval

    Returns void

setLocationPriority

  • setLocationPriority(priority: number): void
  • en

    set location priority, value: com.huawei.hms.location.LocationRequest

    zh

    设置优先级,如果请求GPS位置,则值为100;如请求网络位置,则值为102或104;如不需要主动请求位置,仅需被动接收位置,则值为105。如果请求高精度位置信息,则值为200。

    example
    huawei.hms.location.locationService.setLocationPriority(100);
    

    Parameters

    • priority: number

    Returns void

setMockLocation

  • setMockLocation(lon: number, lat: number): void
  • en

    set mock location

    zh

    设置虚拟定位的信息

    Parameters

    • lon: number

      longitude

    • lat: number

      latitude

    Returns void

setMockMode

  • setMockMode(flag: boolean): void
  • en

    set mock mode

    zh

    设置虚拟定位的开关

    example
    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);
    

    Parameters

    • flag: boolean

      true is open ,false is close

    Returns void

targetOff

  • targetOff(target_node: any): void
  • en

    remove all event listener for the node

    zh

    取消某个节点所有的事件监听

    example
    huawei.hms.location.locationService.targetOff(this);
    

    Parameters

    • target_node: any

    Returns void

Generated using TypeDoc