{"id":18207555,"url":"https://github.com/ybfacc/react-native-position","last_synced_at":"2025-04-02T16:31:10.955Z","repository":{"id":258416386,"uuid":"874883601","full_name":"YBFACC/react-native-position","owner":"YBFACC","description":"react-native Location library, supporting Android and Huawei HMS positioning.","archived":false,"fork":false,"pushed_at":"2024-11-16T10:30:58.000Z","size":1474,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T06:51:41.453Z","etag":null,"topics":["geolocation","hms-location","location","react-native"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YBFACC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-18T16:29:02.000Z","updated_at":"2024-11-24T14:53:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"b062e10b-bbbb-4b39-9d28-1e0da8818465","html_url":"https://github.com/YBFACC/react-native-position","commit_stats":null,"previous_names":["ybfacc/react-native-position"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Freact-native-position","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Freact-native-position/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Freact-native-position/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YBFACC%2Freact-native-position/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YBFACC","download_url":"https://codeload.github.com/YBFACC/react-native-position/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246850868,"owners_count":20844156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geolocation","hms-location","location","react-native"],"created_at":"2024-11-03T13:03:26.931Z","updated_at":"2025-04-02T16:31:10.404Z","avatar_url":"https://github.com/YBFACC.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-position\n\n通过 `Android’s Location API` 和 `HMS Location REST API` 获取位置信息。\n\n解决 `Google’s Location Services API` 无法使用时,也能获取位置信息。\n\n## 优势\n\n-   不需要集成第三方 SDK, 只需要调用 Https 请求\n-   由于 HMS 不需要商业授权, 只需要按量付费([HMS 位置服务](https://developer.huawei.com/consumer/cn/doc/HMSCore-References/web-network-location-0000001051602603))([安卓定位方案的价格对比](http://www.likehide.com/blogs/android/location_server/))\n\n## 实现原理\n\n1. 可获取附近的 `wifi` 信息时, 通过 `HMS Location REST API` 请求位置\n2. 无 `wifi` 信息时, 尝试 `Android’s Location API` 请求\n3. 保底情况, 通过 `cell` 信息 `HMS Location REST API` 请求位置\n\n## 必要准备\n\n1. [注册华为开发者账号](https://developer.huawei.com/consumer/cn/doc/start/registration-and-verification-0000001053628148)\n2. [创建项目](https://developer.huawei.com/consumer/cn/doc/app/agc-help-createproject-0000001100334664)和[创建应用](https://developer.huawei.com/consumer/cn/doc/app/agc-help-createapp-0000001146718717)\n3. 获取到 `apiKey`![screenshot-20241020-051107](https://github.com/user-attachments/assets/4dd30de6-a541-46e0-9ed8-38be44b3754a)\n4. `GNSS` 需要`\u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e`和`\u003cuses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" /\u003e`权限\n5. `wifi` 需要 `\u003cuses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\" /\u003e` 和 `\u003cuses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\" /\u003e`权限\n6. `cell` 需要 `\u003cuses-permission android:name=\"android.permission.READ_PHONE_STATE\" /\u003e`权限\n\n## 使用\n\n```sh\nnpm install react-native-position\n```\n\n```ts\nimport { PermissionsAndroid } from 'react-native'\nimport { getCurrentPosition } from 'react-native-position'\n\nconst getLocation = async () =\u003e {\n    const granteds = await PermissionsAndroid.requestMultiple([\n        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,\n        PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\n        PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE,\n    ])\n    if (\n        granteds['android.permission.ACCESS_FINE_LOCATION'] !== 'granted' ||\n        granteds['android.permission.ACCESS_COARSE_LOCATION'] !== 'granted' ||\n        granteds['android.permission.READ_PHONE_STATE'] !== 'granted'\n    ) {\n        console.log('权限拒绝')\n        return\n    }\n\n    return await getCurrentPosition({\n        hmsKey: 'your hms key',\n        GNSStimeout: 5000,\n    })\n}\n```\n\n## 注意事项\n\n1. 使用 `HMS` 服务中需要遵守[关于华为开发者联盟与隐私的声明](https://developer.huawei.com/consumer/cn/devservice/term)\n2. 尽量保证 `Android 10 (API 29)` 以上\n3. `mnc` \u003c 10 时, 需要设置为 0(HMS 奇怪的配置)\n\n## TODO\n\n-   [ ] ios 实现\n-   [x] 附近 wifi 或基站信息获取, 加强网络定位\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## License\n\nMIT\n\n---\n\nMade with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybfacc%2Freact-native-position","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fybfacc%2Freact-native-position","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fybfacc%2Freact-native-position/lists"}