[英]Get city place id from Google Places API
My app has a search for cities, but when the user enters the full address, he gets placeId
that is more specific than a city -- for an address, or a business. 我的应用程序搜索城市,但是当用户输入完整的地址时,他获得的placeId
比城市更具体-用于地址或企业。 I want the placeId
for the city to store in my database. 我希望将城市的placeId
存储在数据库中。
I'm using Geocomplete http://ubilabs.github.io/geocomplete/ 我正在使用Geocomplete http://ubilabs.github.io/geocomplete/
$('input[name="address"]').geocomplete().bind('geocode:result', function(event, result){
console.log(result.place_id)
});
I need to get place_id
city from place_id
address and check validity in PHP. 我需要从place_id
地址获取place_id
城市,并在PHP中检查有效性。
You can avoid results that represent full addresses by using types
to (regions)
or (cities)
, see details here . 您可以通过使用(regions)
或(cities)
types
来避免代表完整地址的结果,请参见此处的详细信息。
Whether to use one or the other will depend on which countries you want results from, because sometimes cities can be administrative_area1
(eg Tokyo), see the note in the Place Autocomplete Address Form example. 是否使用一个或另一个取决于您想要来自哪个国家/地区,因为有时城市可以是administrative_area1
(例如Tokyo),请参见“ 放置自动填充地址表格”示例中的注释。
根据geocomplete的文档,将触发事件geocode:result
并显示此处描述的结果 ,您需要查看此处描述的address_components
并使用administrative_area
字段之一
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.