{"id":1105,"date":"2015-12-25T14:38:52","date_gmt":"2015-12-25T06:38:52","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1105"},"modified":"2026-08-18T12:58:46","modified_gmt":"2026-08-18T04:58:46","slug":"%e7%99%be%e5%ba%a6%e5%9c%b0%e5%9b%be%e5%bc%80%e5%8f%91%e4%b9%8b%e5%ae%9a%e4%bd%8d%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1105","title":{"rendered":"\u767e\u5ea6\u5730\u56fe\u5f00\u53d1\u4e4b\u5b9a\u4f4d\u529f\u80fd"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\">\u5730\u56fe\u5df2\u7ecf\u662f\u65e5\u5e38\u521a\u9700\uff1a\u51fa\u95e8\u5148\u67e5\u4f4d\u7f6e\uff0c\u624b\u673a\u5730\u56fe\u5219\u8ba9\u5b9a\u4f4d\u968f\u65f6\u53ef\u7528\u3002\u4e0b\u9762\u7528\u767e\u5ea6\u5730\u56fe Android \u5b9a\u4f4d SDK \u628a\u624b\u673a\u5b9a\u4f4d\u8dd1\u901a\uff1a\u5bc6\u94a5\u3001so\/jar\u3001Manifest\u3001LocationClient\u3002<\/p>\n<\/blockquote>\n<p><!--more--><\/p>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e00\u3001\u51c6\u5907\u5de5\u4f5c<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u5f00\u53d1\u5165\u53e3\uff1a<a href=\"http:\/\/developer.baidu.com\/map\">http:\/\/developer.baidu.com\/map<\/a>\uff0c\u9009 Android\uff0c\u518d\u8fdb\u5b9a\u4f4d\u6a21\u5757\u6309\u6587\u6863\u8d70\u3002<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u83b7\u53d6\u5bc6\u94a5\uff0c\u89c1\u5b98\u65b9\u6587\u6863 <a href=\"http:\/\/developer.baidu.com\/map\/index.php?title=androidsdk\/guide\/key\">\u7533\u8bf7\u5bc6\u94a5<\/a><\/section>\n<\/li>\n<li>\n<section>\u4e0b\u8f7d\u5f00\u53d1\u5305\u3002\u6ce8\u610f .so \u4e0e jar \u7248\u672c\u5fc5\u987b\u914d\u5957<\/section>\n<\/li>\n<li>\n<section>\u5728 AndroidManifest \u5199\u5165 Key\u3001\u5b9a\u4f4d Service\u3001\u6743\u9650<\/section>\n<\/li>\n<\/ul>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e8c\u3001Manifest\uff1aKey\u3001Service\u3001\u6743\u9650<\/span><\/h2>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">1. application \u91cc\u5199\u5165 API Key<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;meta-data\n    android:name=&quot;com.baidu.lbsapi.API_KEY&quot;\n    android:value=&quot;\u4f60\u7533\u8bf7\u7684Key&quot; \/&gt;<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">2. \u5b9a\u4f4d\u670d\u52a1<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;service\n    android:name=&quot;com.baidu.location.f&quot;\n    android:enabled=&quot;true&quot;\n    android:process=&quot;:remote&quot;&gt;&lt;\/service&gt;<\/code><\/pre>\n<h3 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">3. \u58f0\u660e\u4f7f\u7528\u6743\u9650<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;!-- \u8fd9\u4e2a\u6743\u9650\u7528\u4e8e\u8fdb\u884c\u7f51\u7edc\u5b9a\u4f4d --&gt;\n&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u8fd9\u4e2a\u6743\u9650\u7528\u4e8e\u8bbf\u95eeGPS\u5b9a\u4f4d --&gt;\n&lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u7528\u4e8e\u8bbf\u95eewifi\u7f51\u7edc\u4fe1\u606f\uff0cwifi\u4fe1\u606f\u4f1a\u7528\u4e8e\u8fdb\u884c\u7f51\u7edc\u5b9a\u4f4d --&gt;\n&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u83b7\u53d6\u8fd0\u8425\u5546\u4fe1\u606f\uff0c\u7528\u4e8e\u652f\u6301\u63d0\u4f9b\u8fd0\u8425\u5546\u4fe1\u606f\u76f8\u5173\u7684\u63a5\u53e3 --&gt;\n&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u8fd9\u4e2a\u6743\u9650\u7528\u4e8e\u83b7\u53d6wifi\u7684\u83b7\u53d6\u6743\u9650\uff0cwifi\u4fe1\u606f\u4f1a\u7528\u6765\u8fdb\u884c\u7f51\u7edc\u5b9a\u4f4d --&gt;\n&lt;uses-permission android:name=&quot;android.permission.CHANGE_WIFI_STATE&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u7528\u4e8e\u8bfb\u53d6\u624b\u673a\u5f53\u524d\u7684\u72b6\u6001 --&gt;\n&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u5199\u5165\u6269\u5c55\u5b58\u50a8\uff0c\u5411\u6269\u5c55\u5361\u5199\u5165\u6570\u636e\uff0c\u7528\u4e8e\u5199\u5165\u79bb\u7ebf\u5b9a\u4f4d\u6570\u636e --&gt;\n&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;&gt;&lt;\/uses-permission&gt;\n&lt;!-- \u8bbf\u95ee\u7f51\u7edc\uff0c\u7f51\u7edc\u5b9a\u4f4d\u9700\u8981\u4e0a\u7f51 --&gt;\n&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; \/&gt;\n&lt;!-- SD\u5361\u8bfb\u53d6\u6743\u9650\uff0c\u7528\u6237\u5199\u5165\u79bb\u7ebf\u5b9a\u4f4d\u6570\u636e --&gt;\n&lt;uses-permission android:name=&quot;android.permission.MOUNT_UNMOUNT_FILESYSTEMS&quot;&gt;&lt;\/uses-permission&gt;<\/code><\/pre>\n<hr>\n<h2 style=\"margin: 1.2em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em; border-bottom: 2px solid #ef7060; display: flex;\"><span style=\"display: inline-block; font-weight: bold; background: #ef7060; color: #ffffff; padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;\">\u4e09\u3001LocationClient \u4ee3\u7801<\/span><\/h2>\n<p style=\"margin: 1em 0px;\">\u9ad8\u7cbe\u5ea6\u6a21\u5f0f\u3001\u5750\u6807\u7cfb <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">gcj02<\/code>\u3001\u626b\u63cf\u95f4\u9694 1000ms\uff08\u6ce8\u91ca\u91cc\u66fe\u5199 5000ms\uff0c\u4ee5\u4ee3\u7801\u4e3a\u51c6\uff09\u3001\u9700\u8981\u5730\u5740\u4fe1\u606f\uff0c\u7136\u540e <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">start()<\/code> \u5e76\u6ce8\u518c <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; font-size: 0.9em; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: #ef7060; background-color: rgba(27, 31, 35, 0.05); word-break: break-all;\">BDLocationListener<\/code>\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 10px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 10px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; margin: 0.5em; padding: 3px 5px; overflow-x: auto; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">{\n    LocationClient mLocationClient = new LocationClient(this.getApplicationContext());\n\n    LocationClientOption option = new LocationClientOption();\n    option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);\/\/\u8bbe\u7f6e\u5b9a\u4f4d\u6a21\u5f0f\n    option.setCoorType(&quot;gcj02&quot;);\/\/\u8fd4\u56de\u7684\u5b9a\u4f4d\u7ed3\u679c\u662f\u767e\u5ea6\u7ecf\u7eac\u5ea6\uff0c\u9ed8\u8ba4\u503cgcj02\n    option.setScanSpan(1000);\/\/\u8bbe\u7f6e\u53d1\u8d77\u5b9a\u4f4d\u8bf7\u6c42\u7684\u95f4\u9694\u65f6\u95f4\u4e3a1000ms\n    option.setIsNeedAddress(true);\n    mLocationClient.setLocOption(option);\n    mLocationClient.start();\n\n    mLocationClient.registerLocationListener(new BDLocationListener() {\n        @Override\n        public void onReceiveLocation(BDLocation location) {\n            Log.i(&quot;tag&quot;, &quot;onReceiveLocation &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;);\n            StringBuffer sb = new StringBuffer(256);\n            sb.append(&quot;time : &quot;);\n            sb.append(location.getTime());\n            sb.append(&quot;\\nerror code : &quot;);\n            sb.append(location.getLocType());\n            sb.append(&quot;\\nlatitude : &quot;);\n            sb.append(location.getLatitude());\n            sb.append(&quot;\\nlontitude : &quot;);\n            sb.append(location.getLongitude());\n            sb.append(&quot;\\nradius : &quot;);\n            sb.append(location.getRadius());\n            if (location.getLocType() == BDLocation.TypeGpsLocation) {\n                sb.append(&quot;\\nspeed : &quot;);\n                sb.append(location.getSpeed());\n                sb.append(&quot;\\nsatellite : &quot;);\n                sb.append(location.getSatelliteNumber());\n                sb.append(&quot;\\ndirection : &quot;);\n                sb.append(&quot;\\naddr : &quot;);\n                sb.append(location.getAddrStr());\n                sb.append(location.getDirection());\n            } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {\n                sb.append(&quot;\\naddr : &quot;);\n                sb.append(location.getAddrStr());\n                sb.append(&quot;\\noperationers : &quot;);\n                sb.append(location.getOperators());\n            }\n            logMsg(sb.toString());\n            Log.e(&quot;tag&quot;, sb.toString());\n        }\n    });\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6700\u65b0\u793a\u4f8b\u89c1\u5b98\u65b9\u6587\u6863\uff1a<a href=\"http:\/\/developer.baidu.com\/map\/index.php?title=android-locsdk\/guide\/v5-0\">Android \u5b9a\u4f4d SDK \u6307\u5357<\/a>\u3002<\/p>\n<table style=\"border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; text-align: left; overflow: auto; display: table; overflow-wrap: break-word; word-break: break-all;\" width=\"817\">\n<thead>\n<tr>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u6b65\u9aa4<\/th>\n<th style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top; font-weight: bold; background-color: #fff9f9; color: #ef7060;\">\u8981\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u5bc6\u94a5<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">meta-data\uff1acom.baidu.lbsapi.API_KEY<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">so \/ jar<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u7248\u672c\u5fc5\u987b\u914d\u5957<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">Service<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">com.baidu.location.f\uff0c\u72ec\u7acb :remote \u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u6743\u9650<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u7c97\u5b9a\u4f4d\u3001\u7cbe\u5b9a\u4f4d\u3001Wi-Fi\u3001\u7f51\u7edc\u3001\u8bfb\u5199\u5b58\u50a8\u3001INTERNET<\/td>\n<\/tr>\n<tr>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">\u4ee3\u7801<\/td>\n<td style=\"font-size: 0.75em; padding: 9px 12px; line-height: 22px; border: 1px solid #ef7060; vertical-align: top;\">LocationClient + Option + BDLocationListener<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote style=\"margin: 20px 0px; display: block; font-size: 0.9em; overflow: auto; border-left: 3px solid #ef7060; color: #6a737d; padding: 10px 10px 10px 20px; background: #fff9f9;\">\n<p style=\"margin: 1em 0px;\"><strong>\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u767e\u5ea6\u5b9a\u4f4d\u4e09\u4ef6\u5957\uff1a\u914d\u5957 SDK\u3001Manifest \u914d\u9f50 Key\/Service\/\u6743\u9650\uff0c\u518d\u7528 LocationClient \u6536\u7ecf\u7eac\u5ea6\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u5730\u56fe\u5df2\u7ecf\u662f\u65e5\u5e38\u521a\u9700\uff1a\u51fa\u95e8\u5148\u67e5\u4f4d\u7f6e\uff0c\u624b\u673a\u5730\u56fe\u5219\u8ba9\u5b9a\u4f4d\u968f\u65f6\u53ef\u7528\u3002\u4e0b\u9762\u7528\u767e\u5ea6\u5730\u56fe Android \u5b9a\u4f4d SDK \u628a\u624b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1105"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1105"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1105\/revisions"}],"predecessor-version":[{"id":3701,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1105\/revisions\/3701"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}