{"id":49,"date":"2015-06-02T15:42:54","date_gmt":"2015-06-02T07:42:54","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=49"},"modified":"2015-06-02T15:42:54","modified_gmt":"2015-06-02T07:42:54","slug":"google-map-api","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=49","title":{"rendered":"[ Google ] &#8211; \u900f\u904e google map api \u8f38\u5165\u5730\u5740 \u56de\u50b3 \u7e23\u5e02\/\u5340 \u7d93 \u7def \u5ea6"},"content":{"rendered":"<p>\t\t\t\t[php]<br \/>\n&lt;?php<br \/>\nfunction getAddress_info($address){<br \/>\n\t\t$info=array(&#8221;,&#8221;,&#8221;,&#8221;);<br \/>\n\t\t$ch = curl_init();<br \/>\n\t\t$options = array(CURLOPT_URL =&gt; &#8216;http:\/\/maps.googleapis.com\/maps\/api\/geocode\/json?address=&#8217;.$address.&#8217;&amp;sensor=false&amp;language=zh-TW&#8217;,<br \/>\n\t\tCURLOPT_HEADER =&gt; false,<br \/>\n\t\tCURLOPT_RETURNTRANSFER =&gt; true,<br \/>\n\t\tCURLOPT_USERAGENT =&gt; &quot;Google Bot&quot;,<br \/>\n\t\tCURLOPT_FOLLOWLOCATION =&gt; true<br \/>\n\t\t);<br \/>\n\t\tcurl_setopt_array($ch, $options);<br \/>\n\t\t$output = curl_exec($ch);<br \/>\n\t\tcurl_close($ch);<br \/>\n\t\t$data=json_decode($output,true);<br \/>\n        \/\/print_r($data);\u770b\u6240\u6709\u50b3\u56de\u7684\u8cc7\u6599<br \/>\n\t\t$info[0]=$data[&#8216;results&#8217;][0][&#8216;address_components&#8217;][4][&#8216;long_name&#8217;];\/\/\u53d6\u5f97\u7e23\u5e02<br \/>\n\t\t$info[1]= $data[&#8216;results&#8217;][0][&#8216;address_components&#8217;][3][&#8216;long_name&#8217;];\/\/\u53d6\u5f97\u5340<br \/>\n\t\t$info[2]= $data[&#8216;results&#8217;][0][&#8216;geometry&#8217;][&#8216;location&#8217;][&#8216;lat&#8217;];\/\/\u53d6\u5f97\u7def\u5ea6<br \/>\n\t\t$info[3]= $data[&#8216;results&#8217;][0][&#8216;geometry&#8217;][&#8216;location&#8217;][&#8216;lng&#8217;];\/\/\u53d6\u5f97\u7d93\u5ea6<br \/>\n\t\treturn $info;<br \/>\n}<br \/>\n$a=getAddress_info(&#8216;\u53f0\u5317\u5e02\u6c11\u6b0a\u897f\u8def104\u865f10\u6a13&#8217;);<br \/>\nprint_r($a);<br \/>\n?&gt;<br \/>\n[\/php]<br \/>\n<strong>\u986f\u793a\u7684\u7d50\u679c\uff1a<\/strong><br \/>\nArray ( [0] => \u53f0\u5317\u5e02 [1] => \u5927\u540c\u5340 [2] => 25.0627169 [3] => 121.5174323 )<br \/>\n\u9700\u5b89\u88ddcurl\u624d\u80fd\u57f7\u884c\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[php] &lt;?php function g&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,36],"tags":[112,287,384,448,753,1089],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-google","category-php","tag-api","tag-google","tag-map","tag-php","tag-753","tag-1089"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=49"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}