From afb44b7a737c0cb9a961a13de79d81021fe16f2a Mon Sep 17 00:00:00 2001 From: liu-binjun Date: Wed, 9 Mar 2022 16:08:29 +0800 Subject: [PATCH 1/2] add system.d.ts file Signed-off-by: liu-binjun --- api/@system.geolocation.d.ts | 162 +++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 api/@system.geolocation.d.ts diff --git a/api/@system.geolocation.d.ts b/api/@system.geolocation.d.ts new file mode 100644 index 0000000000..cd1b299bfb --- /dev/null +++ b/api/@system.geolocation.d.ts @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @syscap SystemCapability.Location.Location.Lite + */ +export interface GeolocationResponse { + /** + * Longitude. + * @since 3 + */ + longitude: number; + + /** + * Latitude. + * @since 3 + */ + latitude: number; + + /** + * Altitude. + * @since 3 + */ + altitude: number; + + /** + * Location accuracy. + * @since 3 + */ + accuracy: number; + + /** + * Time when the location is obtained. + * @since 3 + */ + time: number; +} + +/** + * @syscap SystemCapability.Location.Location.Lite + */ +export interface GetLocationTypeResponse { + /** + * Available location types, ['gps', 'network']. + * @since 3 + */ + types: Array; +} + +/** + * @syscap SystemCapability.Location.Location.Lite + */ +export default class Geolocation { + /** + * Obtains the geographic location. + * @param options + */ + static getLocation(options?: { + /** + * Timeout duration, in milliseconds. The default value is 30000. + * The timeout duration is necessary in case no result is returned if the request to obtain the geographic location is rejected for the lack of the required permission, weak positioning signal, or incorrect location settings. After the timeout duration expires, the fail function will be called. + * The value is a 32-digit positive integer. If the value set is less than or equal to 0, the default value will be used. + * @since 3 + */ + timeout?: number; + + /** + * Coordinate system type. Available types can be obtained by getSupportedCoordTypes. The default type is wgs84. + * @since 3 + */ + coordType?: string; + + /** + * Called when the geographic location is obtained. + * @since 3 + */ + success?: (data: GeolocationResponse) => void; + + /** + * Called when the location types fail to be obtained + * @since 3 + */ + fail?: (data: any, code: number) => void; + + /** + * Called when the execution is completed. + * @since 3 + */ + complete?: () => void; + }): void; + + /** + * Obtains the supported location types. + * @param options + */ + static getLocationType(options?: { + /** + * Called when the location types are obtained. + * @since 3 + */ + success?: (data: GetLocationTypeResponse) => void; + + /** + * Called when the location types fail to be obtained. + * @since 3 + */ + fail?: (data: any, code: number) => void; + + /** + * Called when the execution is completed. + * @since 3 + */ + complete?: () => void; + }): void; + + /** + * Listens to the geographical location. If this method is called multiple times, the last call takes effect. + * @param options + */ + static subscribe(options: { + /** + * Coordinate system type. Available types can be obtained by getSupportedCoordTypes. The default type is wgs84. + * @since 3 + */ + coordType?: string; + + /** + * Called when the geographical location changes. + * @since 3 + */ + success: (data: GeolocationResponse) => void; + + /** + * Called when the listening fails. + * @since 3 + */ + fail?: (data: any, code: number) => void; + }): void; + + /** + * Cancels listening to the geographical location. + */ + static unsubscribe(): void; + + /** + * Obtains coordinate system types supported by the device. + * @returns A string array of the supported coordinate system types. For details about the value, see coordType. + */ + static getSupportedCoordTypes(): Array; +} -- Gitee From e8225cc945a27ee15cfe6fce0c565158292081b8 Mon Sep 17 00:00:00 2001 From: liu-binjun Date: Thu, 10 Mar 2022 18:12:37 +0800 Subject: [PATCH 2/2] fix spelling error Signed-off-by: liu-binjun --- api/@ohos.geolocation.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/@ohos.geolocation.d.ts b/api/@ohos.geolocation.d.ts index 0f04d4073d..51ca8f66f7 100644 --- a/api/@ohos.geolocation.d.ts +++ b/api/@ohos.geolocation.d.ts @@ -75,7 +75,7 @@ declare namespace geolocation { * @param request Indicates the cached GNSS locations request parameters. * @param callback Indicates the callback for reporting the cached GNSS locations. */ - function on(type: 'cachedGnssLocationsReporting', request: CachedGnssLoactionsRequest, callback: Callback>) : void; + function on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback>) : void; /** * unsubscribe to cache GNSS locations update messages @@ -309,7 +309,7 @@ declare namespace geolocation { * @syscap SystemCapability.Location.Location.Gnss * @permission ohos.permission.LOCATION */ - export interface CachedGnssLoactionsRequest { + export interface CachedGnssLocationsRequest { reportingPeriodSec: number; wakeUpCacheQueueFull: boolean; } -- Gitee