I am trying to find a way to assign the JSON value Google Map's API Returns when passed an address. I would search Google, but I am only a few month deep into PHP and really don't know what keywords to use. I really don't even know what a JSON is?
我正在尝试找到一种方法来在传递地址时分配JSON值Google Map的API返回。我会搜索谷歌,但我只有几个月深入PHP,真的不知道使用什么关键字。我真的不知道JSON是什么?
Anyway, I found this article that explains how to query Google Maps with an address and have it return a GPS Location. When I tested it in my browser, the text appears. I just don't know what to use to take what the browser is displaying and assign in to an Object in a PHP page.
无论如何,我发现这篇文章解释了如何使用地址查询Google地图并让它返回GPS位置。当我在浏览器中测试它时,会出现文本。我只是不知道如何使用浏览器显示的内容并将其分配给PHP页面中的Object。
This is the Google Maps Query:
这是Google地图查询:
http://maps.google.com/maps/geo?q="ADDRESS"&output=csv&oe=utf8
This my function where I want to use this:
这是我的功能,我想用它:
//Queries Google Map's API with an address and assigns the returned GPS Location
//to this Object
public function build_me($this_address)
{
//Builds the query from the address array to send to the Goole Maps API
$query = $this_address["Line1"].",".$this_address["Line2"].",".
$this_address["City"].",".$this_address["State"].",".$this_address["Zip"];
//Location_Array = http://maps.google.com/maps/geo?q=$query&output=csv&oe=utf8
$this->latitude = //Location_Array['Something'];
$this->longitude = //Location_Array['Something'];
}
This is the article that I am referring to: http://martinsikora.com/how-to-get-gps-coordinates-from-an-address
这是我所指的文章:http://martinsikora.com/how-to-get-gps-coordinates-from-an-address
My question is, how would I go about doing this? Are there any good tutorials on this? Thanks in advance for anyone pointing me in the right direction!
我的问题是,我该怎么做呢?这有什么好的教程吗?提前感谢任何指点我正确方向的人!
1 个解决方案
#1
4
Actually the URL you are showing will produce a CSV output (that is why it has the output=csv
parameter). You can see it if you simply insert it into your browser (Downing Street 10):
实际上,您显示的URL将生成CSV输出(这就是它具有output = csv参数的原因)。如果您只是将其插入浏览器(Downing Street 10),您就可以看到它:
200,8,45.9797693,-66.5854067
200,8,45.9797693,-66.5854067
Here are some useful resources to get the job done:
以下是完成工作的一些有用资源:
- cURL to make the call to the Google API
- cURL用于调用Google API
- cURL Tutorial
- cURL教程
-
str_getcsv()
to parse a CSV string into a PHP array - str_getcsv()将CSV字符串解析为PHP数组
- (
json_decode()
to translate JSON to PHP arrays/objects - just in case you're gonna need it later) - (json_decode()将JSON转换为PHP数组/对象 - 以防万一你以后需要它)
#1
4
Actually the URL you are showing will produce a CSV output (that is why it has the output=csv
parameter). You can see it if you simply insert it into your browser (Downing Street 10):
实际上,您显示的URL将生成CSV输出(这就是它具有output = csv参数的原因)。如果您只是将其插入浏览器(Downing Street 10),您就可以看到它:
200,8,45.9797693,-66.5854067
200,8,45.9797693,-66.5854067
Here are some useful resources to get the job done:
以下是完成工作的一些有用资源:
- cURL to make the call to the Google API
- cURL用于调用Google API
- cURL Tutorial
- cURL教程
-
str_getcsv()
to parse a CSV string into a PHP array - str_getcsv()将CSV字符串解析为PHP数组
- (
json_decode()
to translate JSON to PHP arrays/objects - just in case you're gonna need it later) - (json_decode()将JSON转换为PHP数组/对象 - 以防万一你以后需要它)