通过路径:http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
可以获取到这样的结果:
{ "results" : [ { "address_components" : [ { "long_name" : "1600", "short_name" : "1600", "types" : [ "street_number" ] }, { "long_name" : "Amphitheatre Parkway", "short_name" : "Amphitheatre Pkwy", "types" : [ "route" ] }, { "long_name" : "山景城", "short_name" : "山景城", "types" : [ "locality", "political" ] }, { "long_name" : "圣塔克拉拉县", "short_name" : "圣塔克拉拉县", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "加利福尼亚州", "short_name" : "CA", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "美国", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "94043", "short_name" : "94043", "types" : [ "postal_code" ] } ], "formatted_address" : "1600 Amphitheatre Parkway, 山景城加利福尼亚州 94043美国", "geometry" : { "location" : { "lat" : 37.4219998, "lng" : -122.0839596 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 37.4233487802915, "lng" : -122.0826106197085 }, "southwest" : { "lat" : 37.4206508197085, "lng" : -122.0853085802915 } } }, "types" : [ "street_address" ] } ], "status" : "OK" }这是一些纯文字数据,可以用PHP的file_get_contents函数先获取他们。
然后用json_decode方法进行json数组解析成PHP 数组。
当传递参数给一个URL作为file_get_contents的参数的时候,
可以用http_build_query把已知数组转换成正确格式的URL
public function get_coordination_by_address($address=''){ //get Coordination from address if (!$address) { $address = '1600 Amphitheatre Parkway, Mountain View, CA'; } $sensor = 'false'; //$ch = curl_init('http://maps.google.com/maps/api/geocode/json'); $data = array('address' => $address, 'sensor'=>$sensor); $content = json_decode(file_get_contents('http://maps.google.com/maps/api/geocode/json?'.http_build_query($data))); $location = $content->results[0]->geometry->location; return $location; } public function get_postcode_by_address($address=''){ //get Coordination from address if (!$address) { $address = '1600 Amphitheatre Parkway, Mountain View, CA'; } $sensor = 'false'; //$ch = curl_init('http://maps.google.com/maps/api/geocode/json'); $data = array('address' => $address, 'sensor'=>$sensor); $content = json_decode(file_get_contents('http://maps.google.com/maps/api/geocode/json?'.http_build_query($data))); foreach ($content->results[0]->address_components as $key=>$v) { foreach ($v->types as $keyi=>$vi) { if ($vi == 'postal_code') { return $v->long_name; } } } } public function get_postcode_coordination_by_address($address='') { if (!$address) { $address = '1600 Amphitheatre Parkway, Mountain View, CA'; } $sensor = 'false'; //$ch = curl_init('http://maps.google.com/maps/api/geocode/json'); $data = array('address' => $address, 'sensor'=>$sensor); $content = json_decode(file_get_contents('http://maps.google.com/maps/api/geocode/json?'.http_build_query($data))); $location = $content->results[0]->geometry->location; $result = array(); $result['location'] = $location; foreach ($content->results[0]->address_components as $key=>$v) { foreach ($v->types as $keyi=>$vi) { if ($vi == 'postal_code') { $result['postcode'] = $v->long_name; var_dump($result); return $result; } } } var_dump($result); return $result; }
相关推荐
主要介绍了google在机器人抓取物体中应用深度学习处理,实现机器人自适应抓取物体的方法。 机器人行业的朋友很适合看一下
02014IEEE IE0--Coordination for Linear Multiagent Systems With Dynamic Interaction Topology in the Leader-Following Framework.pdf
EN 50124-1:2017 Railway applications - Insulation coordination -
EN 50124-2:2017 Railway applications - Insulation coordination -
ZooKeeper Wait-free coordination for Internet-scale systems
ch18-Distributed Coordination.ppt
Comparison of the relationship between two measures of visual-motor coordination and academic achievement Psychology in !he Schools Volume 19. October. 1982 COMPARISON OF THE RELATIONSHIP BETWEEN...
DEN0022E-Power-State-Coordination-Interface-BETA
WS-Coordination Specification. E文版的WS-Coordination规范.
D2EHPA-HCl-LA络合萃取分离镨钕的工艺,尹少华,吴文远,针对D2EHPA -HCl 体系中镨钕分离系数较低的问题,研究了含有乳酸的D2EHPA -HCl体系中的料液酸度、乳酸浓度对镨钕分配比,分离系数和萃取�
中文-英文对照文档:【***-javadoc-API文档-中文(简体)-英语-对照版.zip】 jar包下载地址:【***.jar下载地址(官方地址+国内镜像地址).txt】 Maven依赖:【***.jar Maven依赖信息(可用于项目pom.xml).txt】 ...
Localized charge polarization by less-coordination: Rh adatoms, step edges, and added rows,孙长庆,,The revolutionary impact of atomic under-coordination is indeed fascinating, which discriminates ...
WS-Coordination200411
Relationship between the expressive one-word picture vocabulary test and measures of intelligence, receptive vocabulary, and visual-motor coordination in borderline and mildly retarded children ...
基于Agent组织多UAV协调模型的研究,杨善林,罗贺,在UAV系统中,各成员之间的协调是实现系统空中作业的关键,Agent组织是具有自主性、反应性、社会性和主动性的Agent集合,被认为是解��
基于TORCS仿真平台的关于车队协同控制的实验研究,徐志翔,江洁美,本论文是基于TORCS (The Open Racing Vehicle Simulator) 仿真平台的车队协同控实验研究。首先我们根据研究需求搭建了一个实验平台。...
Distributed exponential finite-time coordination of multi-agent systems: containment control and consensus
Synthesis, Structure, and Clathration Ability of the Microporous Three-Dimensional Coordination Polymer [infin]3[[lcub]CuCN(4,4[prime]-bpy)[rcub][hairsp]·[hairsp]2(4,4[prime]-bpy)] ARTIKEL ...
基于混合配体构筑的的具有链状或T形配位环境的银配合物,张亚男,王尧宇,两种新颖的一维配合物{[Ag3(Hbptc)(bpa)2]•H2O}n(1)[Ag2(H2bptc)(bpp)2]n(2) (H4bptc= 3,3′,4,4′-benzophenonetetracarboxylic acid, bpa...
Polymer-immobilized catalysis has many ... We prepared three novel chiral 1,1-bi-2-naphthol-Ti coordination polymers with properly designed ligands and Ti(OiPr)4 under mild conditions. The prepared polym