{"id":157450,"date":"2024-11-02T23:11:17","date_gmt":"2024-11-02T15:11:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/157450\/"},"modified":"2024-11-02T23:11:18","modified_gmt":"2024-11-02T15:11:18","slug":"%e9%ab%98%e5%be%b7%e5%9c%b0%e5%9c%96%ef%bc%9a%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8d%b2%e5%8f%96%e6%94%bb%e7%95%a5%ef%bc%88%e9%ab%98%e5%be%b7%e6%80%8e%e9%ba%bc%e7%8d%b2%e5%be%97%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/157450\/","title":{"rendered":"\u9ad8\u5fb7\u5730\u5716\uff1a\u6578\u64da\u5eab\u7372\u53d6\u653b\u7565\uff08\u9ad8\u5fb7\u600e\u9ebc\u7372\u5f97\u6578\u64da\u5eab\uff09"},"content":{"rendered":"<h1 id=\"%e9%ab%98%e5%be%b7%e5%9c%b0%e5%9c%96%ef%bc%9a%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8d%b2%e5%8f%96%e6%94%bb%e7%95%a5%ef%bc%88%e9%ab%98%e5%be%b7%e6%80%8e%e9%ba%bc%e7%8d%b2%e5%be%97%e6%95%b8%e6%93%9a%e5%ba%ab-WbWlzGEKJq\">\u9ad8\u5fb7\u5730\u5716\uff1a\u6578\u64da\u5eab\u7372\u53d6\u653b\u7565\uff08\u9ad8\u5fb7\u600e\u9ebc\u7372\u5f97\u6578\u64da\u5eab\uff09<\/h1>\n<p>\u9ad8\u5fb7\u5730\u5716\u4f5c\u70ba\u4e2d\u570b\u9818\u5148\u7684\u5730\u5716\u670d\u52d9\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u8c50\u5bcc\u7684\u5730\u7406\u6578\u64da\u548cAPI\u63a5\u53e3\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u5730\u7372\u53d6\u548c\u4f7f\u7528\u5730\u5716\u6578\u64da\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u6709\u6548\u5730\u7372\u53d6\u9ad8\u5fb7\u5730\u5716\u7684\u6578\u64da\u5eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u6280\u5de7\u548c\u5efa\u8b70\u3002<\/p>\n<h2 id=\"%e9%ab%98%e5%be%b7%e5%9c%b0%e5%9c%96%e6%95%b8%e6%93%9a%e5%ba%ab%e6%a6%82%e8%bf%b0-WbWlzGEKJq\">\u9ad8\u5fb7\u5730\u5716\u6578\u64da\u5eab\u6982\u8ff0<\/h2>\n<p>\u9ad8\u5fb7\u5730\u5716\u7684\u6578\u64da\u5eab\u5305\u542b\u4e86\u5927\u91cf\u7684\u5730\u7406\u4fe1\u606f\uff0c\u5305\u62ec\u5730\u9ede\u3001\u8def\u7dda\u3001\u4ea4\u901a\u72c0\u6cc1\u7b49\u3002\u9019\u4e9b\u6578\u64da\u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u5730\u5716\u986f\u793a\uff0c\u9084\u53ef\u4ee5\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5982\u5c0e\u822a\u3001\u4f4d\u7f6e\u670d\u52d9\u548c\u5546\u696d\u5206\u6790\u7b49\u3002<\/p>\n<h2 id=\"%e7%8d%b2%e5%8f%96%e9%ab%98%e5%be%b7%e5%9c%b0%e5%9c%96%e6%95%b8%e6%93%9a%e7%9a%84%e6%ad%a5%e9%a9%9f-WbWlzGEKJq\">\u7372\u53d6\u9ad8\u5fb7\u5730\u5716\u6578\u64da\u7684\u6b65\u9a5f<\/h2>\n<h3 id=\"1-%e8%a8%bb%e5%86%8a%e9%ab%98%e5%be%b7%e9%96%8b%e7%99%bc%e8%80%85%e8%b3%ac%e8%99%9f-WbWlzGEKJq\">1. \u8a3b\u518a\u9ad8\u5fb7\u958b\u767c\u8005\u8cec\u865f<\/h3>\n<p>\u8981\u7372\u53d6\u9ad8\u5fb7\u5730\u5716\u7684\u6578\u64da\uff0c\u9996\u5148\u9700\u8981\u5728\u9ad8\u5fb7\u958b\u767c\u8005\u5e73\u53f0\u4e0a\u8a3b\u518a\u4e00\u500b\u8cec\u865f\u3002\u8a3b\u518a\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\uff0c\u53ea\u9700\u63d0\u4f9b\u57fa\u672c\u7684\u500b\u4eba\u4fe1\u606f\u548c\u806f\u7e6b\u65b9\u5f0f\u3002<\/p>\n<h3 id=\"2-%e5%89%b5%e5%bb%ba%e6%87%89%e7%94%a8%e4%b8%a6%e7%8d%b2%e5%8f%96api-key-WbWlzGEKJq\">2. \u5275\u5efa\u61c9\u7528\u4e26\u7372\u53d6API Key<\/h3>\n<p>\u8a3b\u518a\u5b8c\u6210\u5f8c\uff0c\u767b\u9304\u958b\u767c\u8005\u5e73\u53f0\uff0c\u5275\u5efa\u4e00\u500b\u65b0\u7684\u61c9\u7528\u3002\u5275\u5efa\u61c9\u7528\u5f8c\uff0c\u7cfb\u7d71\u6703\u81ea\u52d5\u751f\u6210\u4e00\u500bAPI Key\uff0c\u9019\u662f\u4f60\u8a2a\u554f\u9ad8\u5fb7\u5730\u5716\u6578\u64da\u7684\u6191\u8b49\u3002\u8acb\u59a5\u5584\u4fdd\u7ba1\u9019\u500bAPI Key\uff0c\u56e0\u70ba\u5b83\u5c07\u5728\u5f8c\u7e8c\u7684API\u8abf\u7528\u4e2d\u4f7f\u7528\u3002<\/p>\n<h3 id=\"3-%e7%80%8f%e8%a6%bdapi%e6%96%87%e6%aa%94-WbWlzGEKJq\">3. \u700f\u89bdAPI\u6587\u6a94<\/h3>\n<p>\u9ad8\u5fb7\u63d0\u4f9b\u4e86\u8a73\u7d30\u7684API\u6587\u6a94\uff0c\u6db5\u84cb\u4e86\u5404\u7a2e\u529f\u80fd\u548c\u6578\u64da\u63a5\u53e3\u3002\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684API\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u5730\u7406\u7de8\u78bcAPI\uff1a<\/strong>\u5c07\u5730\u5740\u8f49\u63db\u70ba\u7d93\u7def\u5ea6\u5750\u6a19\u3002<\/li>\n<li><strong>\u9006\u5730\u7406\u7de8\u78bcAPI\uff1a<\/strong>\u5c07\u7d93\u7def\u5ea6\u5750\u6a19\u8f49\u63db\u70ba\u5730\u5740\u3002<\/li>\n<li><strong>\u8def\u5f91\u898f\u5283API\uff1a<\/strong>\u63d0\u4f9b\u6700\u4f73\u8def\u5f91\u898f\u5283\u670d\u52d9\u3002<\/li>\n<li><strong>\u5468\u908a\u641c\u7d22API\uff1a<\/strong>\u6839\u64da\u6307\u5b9a\u4f4d\u7f6e\u67e5\u627e\u5468\u908a\u7684\u5546\u5bb6\u6216\u5730\u9ede\u3002<\/li>\n<\/ul>\n<h3 id=\"4-%e5%af%a6%e7%8f%beapi%e8%aa%bf%e7%94%a8-WbWlzGEKJq\">4. \u5be6\u73feAPI\u8abf\u7528<\/h3>\n<p>\u5728\u7372\u53d6API Key\u548c\u4e86\u89e3API\u6587\u6a94\u5f8c\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u958b\u59cb\u9032\u884cAPI\u8abf\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528JavaScript\u8abf\u7528\u9ad8\u5fb7\u7684\u5730\u7406\u7de8\u78bcAPI\uff1a<\/p>\n<pre><code>\nconst apiKey = 'YOUR_API_KEY';\nconst address = '\u5317\u4eac\u5e02\u671d\u967d\u5340';\nconst url = `https:\/\/restapi.amap.com\/v3\/geocode\/geo?key=${apiKey}&amp;address=${encodeURIComponent(address)}`;\n\nfetch(url)\n    .then(response =&gt; response.json())\n    .then(data =&gt; {\n        if (data.status === '1') {\n            console.log('\u7d93\u7def\u5ea6:', data.geocodes[0].location);\n        } else {\n            console.error('\u7372\u53d6\u7d93\u7def\u5ea6\u5931\u6557:', data.info);\n        }\n    })\n    .catch(error =&gt; console.error('\u932f\u8aa4:', error));\n<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e4%bd%bf%e7%94%a8%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-WbWlzGEKJq\">\u6578\u64da\u4f7f\u7528\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528\u9ad8\u5fb7\u5730\u5716\u6578\u64da\u6642\uff0c\u958b\u767c\u8005\u9700\u8981\u9075\u5faa\u9ad8\u5fb7\u7684\u4f7f\u7528\u898f\u7bc4\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u65bc\uff1a<\/p>\n<ul>\n<li>\u9075\u5b88API\u8abf\u7528\u7684\u983b\u7387\u9650\u5236\u3002<\/li>\n<li>\u5728\u61c9\u7528\u4e2d\u6b63\u78ba\u986f\u793a\u9ad8\u5fb7\u5730\u5716\u7684\u7248\u6b0a\u4fe1\u606f\u3002<\/li>\n<li>\u4e0d\u5f97\u5c07\u6578\u64da\u7528\u65bc\u975e\u6cd5\u7528\u9014\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-WbWlzGEKJq\">\u7d50\u8ad6<\/h2>\n<p>\u9ad8\u5fb7\u5730\u5716\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u6578\u64da\u5eab\u548cAPI\u63a5\u53e3\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u7372\u53d6\u548c\u4f7f\u7528\u5730\u7406\u6578\u64da\u3002\u901a\u904e\u8a3b\u518a\u958b\u767c\u8005\u8cec\u865f\u3001\u7372\u53d6API Key\u3001\u700f\u89bdAPI\u6587\u6a94\u4ee5\u53ca\u5be6\u73feAPI\u8abf\u7528\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u4e0a\u624b\u4e26\u5229\u7528\u9019\u4e9b\u6578\u64da\u4f86\u63d0\u5347\u61c9\u7528\u7684\u529f\u80fd\u6027\u548c\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684\u4f3a\u670d\u5668\u652f\u6301\u4f86\u904b\u884c\u60a8\u7684\u61c9\u7528\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u9805\u76ee\u63d0\u4f9b\u5f37\u5927\u7684\u5f8c\u7aef\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u9ad8\u5fb7\u5730\u5716\u7684\u6578\u64da\u5eab\u7372\u53d6\u653b\u7565\uff0c\u4e86\u89e3\u5982\u4f55\u6709\u6548\u7372\u5f97\u548c\u5229\u7528\u9ad8\u5fb7\u7684\u6578\u64da\u8cc7\u6e90\uff0c\u63d0\u5347\u5730\u5716\u61c9\u7528\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-157450","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/157450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=157450"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/157450\/revisions"}],"predecessor-version":[{"id":157451,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/157450\/revisions\/157451"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=157450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=157450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=157450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}