{"id":152,"date":"2013-10-27T13:34:32","date_gmt":"2013-10-27T05:34:32","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=152"},"modified":"2015-01-18T19:39:04","modified_gmt":"2015-01-18T11:39:04","slug":"php%e8%8e%b7%e5%8f%96%e5%ae%9e%e9%99%85%e5%9c%b0%e7%90%86%e4%bd%8d%e7%bd%ae%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/My_Log\/152.html","title":{"rendered":"PHP\u83b7\u53d6\u5b9e\u9645\u5730\u7406\u4f4d\u7f6e\u4fe1\u606f"},"content":{"rendered":"<pre class=\"brush:php; toolbar: true; auto-links: true;\">\t\/\/\u901a\u8fc7\u4f20\u9012\"\u7ecf\u5ea6\"\u3001\"\u7eac\u5ea6\"\u83b7\u53d6\u6240\u5728\u5730\u7406\u4f4d\u7f6e\r\n\t\/\/$lat: \u7eac\u5ea6\r\n\t\/\/$lng: \u7ecf\u5ea6\r\n\t\/\/$BaiDu_AK: \u767e\u5ea6AK\u5bc6\u94a5\r\n\tfunction GetLocation($lat, $lng, $BaiDu_AK) {\r\n\t\t$strLocation = \"\";\r\n\t\t$gps_data = file_get_contents(\"http:\/\/api.map.baidu.com\/ag\/coord\/convert?from=0&amp;to=4&amp;x=$lng&amp;y=$lat\");\r\n\t\t$arr = (array)json_decode($gps_data);\r\n\t\t$lat_t = $lng_t = \"\";\r\n\t\tif (!$arr['error']) {\r\n\t\t\t$lat_t = base64_decode($arr['y']);\r\n\t\t\t$lng_t = base64_decode($arr['x']);\r\n\t\t}\r\n\t\tif (strlen($lat_t) &gt; 0 &amp;&amp; strlen($lng_t) &gt; 0) {\r\n\t\t\t$xml = new DOMDocument();\r\n\t\t\t$xml-&gt;load(\"http:\/\/api.map.baidu.com\/geocoder\/v2\/?ak=$BaiDu_AK&amp;callback=renderReverse&amp;location=$lat_t,$lng_t&amp;output=xml&amp;pois=0\");\r\n\t\t\t$result_s = $xml-&gt;getElementsByTagName(\"result\");\r\n\t\t\tforeach($result_s as $result) {\r\n\t\t\t\t$formatted_address_s = $result-&gt;getElementsByTagName(\"formatted_address\");\r\n\t\t\t\t$strLocation = $formatted_address_s-&gt;item(0)-&gt;nodeValue;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (strlen($strLocation) == 0) {\r\n\t\t\t\t$xml = new DOMDocument();\r\n\t\t\t\t$xml-&gt;load(\"http:\/\/maps.233.wiki\/maps\/api\/geocode\/xml?latlng=$lat,$lng&amp;sensor=false&amp;language=zh-CN\");\r\n\t\t\t\t$result_s = $xml-&gt;getElementsByTagName(\"result\");\r\n\t\t\t\tforeach($result_s as $result) {\r\n\t\t\t\t\t$formatted_address_s = $result-&gt;getElementsByTagName(\"formatted_address\");\r\n\t\t\t\t\t$strLocation = $formatted_address_s-&gt;item(0)-&gt;nodeValue;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t}\r\n\t\treturn $strLocation;\r\n\t}\r\n\techo GetLocation(\"39.935377\", \"119.600492\", \"\u81ea\u5df1\u7684\u767e\u5ea6AK\");<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/\u901a\u8fc7\u4f20\u9012\"\u7ecf\u5ea6\"\u3001\"\u7eac\u5ea6\"\u83b7\u53d6\u6240\u5728\u5730\u7406\u4f4d\u7f6e \/\/$lat: \u7eac\u5ea6 \/\/$lng: \u7ecf\u5ea6 \/\/$BaiDu_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[28],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-My_Log","tag-php"],"views":1254,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}