• Home
Name Date Size #Lines LOC

..--

AppScope/12-May-2024-3633

entry/12-May-2024-792641

position/12-May-2024-599497

screenshots/devices/zh/12-May-2024-

.gitignoreD12-May-202456 55

README.mdD12-May-20242.3 KiB3919

README_zh.mdD12-May-20242.3 KiB4120

build-profile.json5D12-May-20241.1 KiB4745

hvigorfile.jsD12-May-2024168 21

package.jsonD12-May-2024372 1918

README.md

1# Geolocation
2
3### Introduction
4
5This sample shows how to use **geolocation** APIs to implement location services.
6
7In this example, we'll use [Geolocation](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-geolocation.md) APIs to obtain the longitude and latitude of the current location, and use [HTTP](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-http.md) APIs to obtain the city where the longitude and latitude are located. With the [AlphabetIndexer](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/arkui-ts/ts-container-alphabet-indexer.md) APIs, we can also quickly locate the container display area based on the logical structure.
8
9How to Use
10
111. Go to the home page and touch a popular city in the popular city list. The delivery address will be updated to the selected city. Alternatively, touch the alphabetic index bar on the right to quickly locate the desired city. If the city is divided into districts, you can click the desired district to update the delivery address to that district.
12
132. If your test device supports the GPS function, you can touch the location icon above the popular city list to locate the city where you settle. The city next to the location icon will be updated accordingly.
14
15
16### Preview
17
18![](screenshots/devices/zh/position.png)
19
20### Required Permissions
21
22Using network sockets: [ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/master/en/application-dev/security/permission-list.md)
23
24Obtaining location information while running in the foreground: [ohos.permission.LOCATION](https://gitee.com/openharmony/docs/blob/master/en/application-dev/security/permission-list.md)
25
26Obtaining location information while running in the background: [ohos.permission.LOCATION_IN_BACKGROUND](https://gitee.com/openharmony/docs/blob/master/en/application-dev/security/permission-list.md)
27
28### Dependency
29
30N/A
31
32### Constraints
33
341. This sample can only be run on standard-system devices. To use GPS positioning, the test device must support the GPS function.
35
362. This sample demonstrates the stage model, which supports only the SDK of API version 9 (SDK version: 3.2.5.5).
37
383. DevEco Studio 3.0 Beta4 (Build version: 3.0.0.992, built on July 14, 2022) must be used.
39

README_zh.md

1# 位置信息
2
3### 介绍
4
5本示例通过**geolocation**实现获取位置信息。
6
7本示例使用 [geolocation](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-geolocation.md) 实现获取当前位置的经纬度,然后通过 [http](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-http.md) 将经纬度作为请求参数,获取到该经纬度所在的城市。通过 [AlphabetIndexer](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/arkui-ts/ts-container-alphabet-indexer.md) 容器组件实现按逻辑结构快速定位容器显示区域。
8
9使用说明:
10
111.进入主页,点击国内热门城市,配送地址会更新为选择的城市。点击右边字母索引条,可快速定位到想要选择的城市区域,点击该城市后若该城市还细化到区,继续点击该城市的区,配送地址会更新为城市/区,若未细化到区,则只选择城市。
12
132.若测试机支持GPS,点击国内热门城市上面的定位图标,应用会获取本机所在经纬度,然后根据经纬度获取所在城市,定位图标后的城市会进行刷新。
14
15
16### 效果预览
17
18![](screenshots/devices/zh/position.png)
19
20### 相关权限
21
22允许使用网络socket:[ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md)
23
24允许应用在前台运行时获取位置信息:[ohos.permission.LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md)
25
26允许应用在后台运行时获取位置信息:[ohos.permission.LOCATION_IN_BACKGROUND](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md)
27
28允许应用获取设备模糊位置信息:[ohos.permission.APPROXIMATELY_LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md)
29
30### 依赖
31
32不涉及。
33
34### 约束与限制
35
361.本示例仅支持标准系统上运行,支持设备:GPS定位功能仅支持部分机型。
37
382.本示例为Stage模型,仅支持API9版本SDK,版本号:3.2.5.5。
39
403.本示例需要使用DevEco Studio 3.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022)才可编译运行。
41