从 Google 个地点 API 获取城市地点 ID
Get city place id from Google Places API
我的应用程序可以搜索城市,但是当用户输入完整地址时,他会得到 placeId
比城市更具体的地址或公司。我希望城市的 placeId
存储在我的数据库中。
我正在使用 Geocomplete http://ubilabs.github.io/geocomplete/
$('input[name="address"]').geocomplete().bind('geocode:result', function(event, result){
console.log(result.place_id)
});
我需要从 place_id
地址获取 place_id
城市并检查 PHP 中的有效性。
基于 geocomplete, event geocode:result
will be triggered with result described here, you need to look in address_components
which is described here 的文档并使用 administrative_area
字段之一
您可以使用 types
到 (regions)
或 (cities)
来避免表示完整地址的结果,请参阅详细信息 here。
是否使用一个或另一个将取决于您想要来自哪个国家/地区的结果,因为有时城市可以是 administrative_area1
(例如东京),请参阅 Place Autocomplete Address Form 示例中的注释。
我的应用程序可以搜索城市,但是当用户输入完整地址时,他会得到 placeId
比城市更具体的地址或公司。我希望城市的 placeId
存储在我的数据库中。
我正在使用 Geocomplete http://ubilabs.github.io/geocomplete/
$('input[name="address"]').geocomplete().bind('geocode:result', function(event, result){
console.log(result.place_id)
});
我需要从 place_id
地址获取 place_id
城市并检查 PHP 中的有效性。
基于 geocomplete, event geocode:result
will be triggered with result described here, you need to look in address_components
which is described here 的文档并使用 administrative_area
字段之一
您可以使用 types
到 (regions)
或 (cities)
来避免表示完整地址的结果,请参阅详细信息 here。
是否使用一个或另一个将取决于您想要来自哪个国家/地区的结果,因为有时城市可以是 administrative_area1
(例如东京),请参阅 Place Autocomplete Address Form 示例中的注释。