首页 > 解决方案 > 如何从 $user.currentLocation 获取用户的社区或城市?

问题描述

我想知道是否有人可以帮助我解决这个问题。如何从 $user.currentLocation 获取用户的社区(或城市)?

我一直在尝试各种事情,并查看了文档,尤其是这里: https ://bixbydevelopers.com/dev/docs/dev-guide/developers/library.geo#searchregion-and-currentlocation 但这不是我正在寻找。

如果用户说:“天气怎么样?” 在不指定地点的情况下,我的 getWeather 操作如下所示:

input (where) {
      min (Optional) max(One)
      type (viv.geo.NamedPoint)
      default-select {
        with-rule {
          select-first
        }
      }
       default-init {
         if ($user.currentLocation.$exists) {
           intent {
             goal: geo.GeoPoint
             value-set: geo.CurrentLocation { $expr ($user.currentLocation) }
           }
         } 
       }

这将为我提供用于天气 API 查询的 long/lat。但我想在视图中显示(虽然不是说)用户当前位置的社区(或城市)。(我相信如果我将目标/值集更改为 SearchRegion,那么我可以获得城市,但不是 $user.currentLocation 的经度/纬度。相反,我得到城市的通用经度/纬度,这不是t足够具体。)

所以,我想要 1) API 的 $user.currentLocation 的经度/纬度和 2) 用于视图的经度/纬度的社区(或城市)。我无法弄清楚如何同时获得两者。

标签: bixbybixbystudio

解决方案


您定义的输入是 aNamedPoint并且NamedPoint.point是 aGeoPoint所以它应该具有您需要的纬度/经度。

要获取城市,NamedPoint.address应该包含一个Address结构来访问街道地址、城市、州、国家等。

另一种选择可能是获取地址的reverseGeo属性。GeoPoint此属性是 a lazy-source,因此在调用此属性之前数据将不可用。


推荐阅读