javascript - 使用 PlacesService 反转地点 ID
问题描述
我正在寻找一种避免被收费的方法
- Places API 大气数据
- Places API 联系数据
我只需要将地点 id 反转为其formatted_address。关于我需要在下面的代码中进行哪些更改的任何想法?
相关问题,虽然我没有使用Autocomplete
但是PlacesService
。
$('.company_location_id').each(function(i, obj) {
if ($(this).length > 0) {
if ($(this).val()) {
var request = {
placeId: $(this).val()
};
service = new google.maps.places.PlacesService(document.getElementsByClassName($(this).attr('class'))[0]);
service.getDetails(request, callback);
var new_text = $(this)
function callback(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
$(new_text).next().text(place.formatted_address);
}
}
}
}
});
解决方案
为了避免使用 对大气数据和联系人数据收费PlacesService
,您应该指定要在PlaceDetailsRequest
作为函数中第一个参数传递的对象中检索的字段列表getDetails()
。
看看PlaceDetailsRequest
接口的文档:
https ://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceDetailsRequest
如您所见,此接口具有fields
属性
fields - 要包含在详细信息响应中的字段。有关字段列表,请参阅 PlaceResult。可以使用点路径指定嵌套字段(例如,“geometry.location”)。
因此,您应该在代码中将 request 定义为
var request = {
placeId: $(this).val(),
fields: ["formatted_address"]
};
我希望这有帮助!
推荐阅读
- java - DLL JAVA调用嵌套DLL方法
- wikipedia - 将 Wikidata QID 映射到 Wikipedia CurID
- typescript - 如何为具有默认导出的模块创建 TSD?
- mysql - Mysql 触发 if 语句更新第二张表
- python - 不同的语法错误隐藏输出中的行
- reactjs - 父组件中的表单提交时如何使子组件更新
- xlc - 我该如何使用#include 来完成这项工作?直接放入代码中时效果很好
- c# - Blazor 子组件模板化/渲染片段问题
- node.js - 在 Fargate 中运行的 Node Web 应用程序在内存和 CPU 相对没有负担的负载下崩溃
- android - 如何修复“在 android studio 中加密 xml 问题或不知道这是什么”