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
相关产品推荐
相关产品推荐

