You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Maps JavaScript Places API searchByText返回异常结构对象问题求助

Google Maps JavaScript Places API searchByText返回异常结构对象问题求助

我在Vue项目里用Vite开发服务器运行时,调用Maps JavaScript API新的Text Search功能里的searchByText()方法获取地点列表,结果返回的结构完全不符合预期!

根据文档和@types/google.maps的类型定义,这个方法应该返回google.maps.places.Place[]类型的结果,但实际拿到的是个结构奇怪的对象——里面全是Fg、Hg、Ig这类看起来像中间处理用的键,真正的Place对象藏在Eg键里,其他键要么是重复的冗余内容,要么大多是undefined。

有没有人碰到过这种情况?目前只在Vite的开发环境测试过,还没尝试其他构建方式。

代码示例

const loader = new Loader({
  apiKey,
  version: '3.58'
});
const places: google.maps.PlacesLibrary = await loader.importLibrary('places');
const request = {
  includedType: 'locality',
  textQuery: 'Bogota',
  fields: ['location', 'formattedAddress', 'types', 'id']
}
const result = await places.Place.searchByText(request);
console.log(result);

返回结果(已省略undefined的键)

{
  "places": [
    {
      "id": "ChIJQycDzk1B1moR7LsQHWG_MKs",
      "Eg": {
        "id": "ChIJQycDzk1B1moR7LsQHWG_MKs",
        "location": {...},
        "formattedAddress": "...",
        "types": [
          "doctor",
          "point_of_interest",
          "health",
          "establishment"
        ]
      },
      "Ng": {},
      "Ug": [
        "doctor",
        "point_of_interest",
        "health",
        "establishment"
      ],
      "Fg": {}
    }
  ]
}

备注:内容来源于stack exchange,提问作者spinkus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 16:09:50