【问题标题】:Is it possible to get the geolocation of user in a webOS TV App?是否可以在 webOS TV App 中获取用户的地理位置?
【发布时间】:2019-03-01 16:01:53
【问题描述】:

我目前正在开发一个 webOS TV Web 应用程序,并希望使用 Geolocation API 获取用户的地理位置。浏览器引擎实现了 API,但是当我在 webOS TV 4.0.0 模拟器上运行我的网络应用程序时,getCurrentPosition 方法会立即执行错误回调,而无需询问用户是否允许知道他们的位置。

这是我正在运行的简单 sn-p:

function success(pos) {
  console.log('Position: ', pos);
}

function error(err) {
  console.log('Err', err)
}

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(success, error);
}   

错误回调输出的内容:

Err Position-error {code: 1, message: "User denied Geolocation"}.

是否可以使用用户的地理位置?还有什么我需要做的吗? API 是否纯粹是装饰性的,不打算在 webOS TV 中使用?

【问题讨论】:

    标签: javascript webos


    【解决方案1】:

    您可以使用可以返回 JSON 的 Web 服务,例如:GeoBytes For more info

    试试看:http://gd.geobytes.com/GetCityDetails

        $.getJSON('http://gd.geobytes.com/GetCityDetails?callback=?', function(data) {
          console.log(JSON.stringify(data, null, 2));
        });
    

    它返回一个包含所有信息的 Json 响应:ip 地址、位置等...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      相关资源
      最近更新 更多