【问题标题】:APIS for ask user location in the broswer (No with window.navigator)用于在浏览器中询问用户位置的 APIS(没有 window.navigator)
【发布时间】:2022-11-22 11:13:57
【问题描述】:

我想知道是否有任何免费或付费的非 Google API 可以让您从浏览器中获得用户的位置,以便与 mapbox gl 和 React 一起使用

我已经知道 window.navigator 和 getCurrentPosition 方法,并获取地理位置

const successCallback = (position) => {
  console.log(position);
};

const errorCallback = (error) => {
  console.log(error);
};

navigator.geolocation.getCurrentPosition(successCallback, errorCallback);

【问题讨论】:

  • 那么 getCurrentPosition 有什么问题呢?

标签: javascript reactjs


【解决方案1】:

你有几个选择。
一个您已经知道并以前引用过的,本地窗口 api。

如您所问,还有一项谷歌服务。

https://developers.google.com/maps/documentation/geolocation/overview
按照链接阅读文档,非常全面。

亚马逊服务
https://aws.amazon.com/pm/location/

和不太准确的 IP 地理定位器。
这是一项服务https://ipgeolocation.io/

【讨论】:

    【解决方案2】:

    访问某人位置(经许可)的最常见方法是使用 Permissions API

    https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API/Using_the_Permissions_API

    【讨论】:

    • 我知道,但我想使用其他 API 来解决国家/地区问题
    猜你喜欢
    • 1970-01-01
    • 2023-02-11
    • 2022-01-02
    • 2022-01-19
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多