更新时间:2023-01-16 13:18:59
请注意,似乎 results
包含一个数组 (此处只有一个项)结果;而geometry
是一个结果中的一项.
Note that it seems that results
contains an array (with only one item in it, here) of results ; and geometry
is one item inside one result.
在这里,您可以看到结果的内容由[]
分隔-表示它是一个数组.
Here, you can see that results' content is delimited by []
-- which indicates it's an array.
因此,您必须首先访问第一个结果:$geoloc['results'][0]
其中将具有以下几何形状:$geoloc['results'][0]['geometry']
So, you have to first access the first result : $geoloc['results'][0]
Inside of which you'll have the geometry : $geoloc['results'][0]['geometry']
这将允许您获取纬度和经度:
Which will allow you to get the latitude and longitude :
var_dump($geoloc['results'][0]['geometry']['location']['lat']);
var_dump($geoloc['results'][0]['geometry']['location']['lng']);
我想根据您搜索的地址,有时results
数组中会有多个项目.
I suppose that, depending on the address you've searched on, you will sometimes have more than one item in the results
array.