{"id":12696,"date":"2022-11-24T15:21:08","date_gmt":"2022-11-24T07:21:08","guid":{"rendered":"https:\/\/www.yimenapp.com\/kb-yimen\/?p=12696"},"modified":"2022-11-24T15:21:08","modified_gmt":"2022-11-24T07:21:08","slug":"%e5%b0%8f%e7%b1%b3%e5%bc%80%e5%8f%91%e5%b9%b3%e5%8f%b0-%e5%85%b3%e4%ba%8e%e6%97%a0gps%e7%a1%ac%e4%bb%b6%e6%9c%ba%e5%9e%8b%e7%9a%84%e4%bd%8d%e7%bd%ae%e6%9c%8d%e5%8a%a1%e9%80%82%e9%85%8d%e8%af%b4","status":"publish","type":"post","link":"https:\/\/www.yimenapp.com\/kb-yimen\/12696\/","title":{"rendered":"\u5c0f\u7c73\u5f00\u53d1\u5e73\u53f0 \u5173\u4e8e\u65e0GPS\u786c\u4ef6\u673a\u578b\u7684\u4f4d\u7f6e\u670d\u52a1\u9002\u914d\u8bf4\u660e"},"content":{"rendered":"\n<p><span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/xiaomi\/\" title=\"\u5c0f\u7c73\" target=\"_blank\">\u5c0f\u7c73<\/a><\/span>\u5f00\u53d1\u5e73\u53f0 \u5173\u4e8e<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/%e6%97%a0gps%e7%a1%ac%e4%bb%b6\/\" title=\"\u65e0GPS\u786c\u4ef6\" target=\"_blank\">\u65e0GPS\u786c\u4ef6<\/a><\/span>\u673a\u578b\u7684\u4f4d\u7f6e\u670d\u52a1\u9002\u914d\u8bf4\u660e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_0\">1.\u80cc\u666f<\/h2>\n\n\n\n<p>\u7531\u4e8e\u90e8\u5206WiFi\u7248\u672c\u7684\u5c0f\u7c73\u5e73\u677f\uff08\u4f8b\u5982\uff1a\u5c0f\u7c73\u5e73\u677f5 WiFi\u7248\u7b49\uff09\u65e0<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/gps%e7%a1%ac%e4%bb%b6\/\" title=\"GPS\u786c\u4ef6\" target=\"_blank\">GPS\u786c\u4ef6<\/a><\/span>\uff0c\u5373\u4f7f\u7528\u6237\u5f00\u542f\u4f4d\u7f6e\u670d\u52a1\uff0c\u5e94\u7528\u4e5f\u65e0\u6cd5\u83b7\u53d6\u5230<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/gps\/\" title=\"GPS\" target=\"_blank\">GPS<\/a><\/span> Provider\uff0c\u90e8\u5206\u4f9d\u8d56\u4e8eGPS\u4f4d\u7f6e\u670d\u52a1\u7684\u5e94\u7528\u53ef\u80fd\u4f1a\u63d0\u793a\u201c\u672a\u5f00\u542f\u4f4d\u7f6e\u670d\u52a1\u6216\u51fa\u73b0\u5176\u4ed6\u95ee\u9898\u201d\uff0c\u7528\u6237\u4f53\u9a8c\u8f83\u5dee\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_1\">2.\u9002\u914d\u8bf4\u660e<\/h2>\n\n\n\n<p>\u9488\u5bf9\u65e0GPS\u786c\u4ef6\u7684\u673a\u578b\uff0c\u5e94\u7528\u53ef\u4ee5\u901a\u8fc7\u68c0\u6d4b<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/location-proveders\/\" title=\"Location Proveders\" target=\"_blank\">Location Proveders<\/a><\/span>\u4e2d\u662f\u5426\u5305\u542b&#8221;gps&#8221;\u6765\u5224\u65ad\u662f\u5426\u6709GPS\u786c\u4ef6\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7\u68c0\u6d4b<span class=\"wpcom_tag_link\"><a href=\"https:\/\/www.yimenapp.com\/kb-yimen\/tag\/network-provider\/\" title=\"Network Provider\" target=\"_blank\">Network Provider<\/a><\/span>\u72b6\u6001\u6765\u5224\u65ad\u7528\u6237\u662f\u5426\u6253\u5f00\u4f4d\u7f6e\u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u53c2\u8003Demo\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);\n<em>\/\/ \u65e0GPS\u8bbe\u5907\u901a\u8fc7\u5224\u65adNetwork Provider\u6765\u5224\u65ad\u4f4d\u7f6e\u670d\u52a1\u662f\u5426\u6253\u5f00<\/em>\n<em>\/\/ \u5176\u4ed6\u8bbe\u5907\u4ecd\u7136\u901a\u8fc7GPS Provider\u6765\u5224\u65ad\u4f4d\u7f6e\u670d\u52a1\u662f\u5426\u6253\u5f00<\/em>\n<strong>if<\/strong> (!isGPSExist(lm) &amp;&amp; isNetworkLocationAble(lm) || isGpsAble(lm)) {\n    <em>\/\/ \u7528\u6237\u5df2\u5f00\u542f\u4f4d\u7f6e\u670d\u52a1<\/em>\n    <em>\/\/ \u5e94\u7528\u81ea\u8eab\u5b9a\u4f4d\u903b\u8f91<\/em>\n} <strong>else<\/strong> {\n    <em>\/\/ \u63d0\u9192\u7528\u6237\u672a\u5f00\u542f\u4f4d\u7f6e\u670d\u52a1\uff0c\u5f15\u5bfc\u7528\u6237\u81f3\u4f4d\u7f6e\u670d\u52a1\u8bbe\u7f6e\u9875\u9762<\/em>\n    openLocationService();\n}\n\n<em>\/\/ \u5e94\u7528\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5224\u65ad\u662f\u5426\u6709GPS\u786c\u4ef6<\/em>\n<strong>public<\/strong> <strong>static<\/strong> <strong>boolean<\/strong> <strong>isGPSExist<\/strong>(LocationManager lm) {\n    <strong>return<\/strong> lm.getAllProviders().contains(\"gps\");\n}\n\n<strong>private<\/strong> <strong>boolean<\/strong> <strong>isGpsAble<\/strong>(LocationManager lm){\n    <strong>return<\/strong> lm.isProviderEnabled(LocationManager.GPS_PROVIDER);\n}\n\n<strong>private<\/strong> <strong>boolean<\/strong> <strong>isNetworkLocationAble<\/strong>(LocationManager lm){\n     <strong>return<\/strong> lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);\n}\n\n<strong>private<\/strong> <strong>void<\/strong> <strong>openLocationService<\/strong>()(){\n    Intent intent = <strong>new<\/strong> Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);\n    startActivity(intent);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_2\">3.\u4f18\u5316\u5efa\u8bae<\/h2>\n\n\n\n<p>\u5982\u679c\u5e94\u7528\u5bf9GPS\u6709\u5f3a\u4f9d\u8d56\uff0c\u5efa\u8bae\u5e94\u7528\u4f18\u5316\u65b0\u589e\u76f8\u5173\u53cb\u597d\u63d0\u793a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8e\u90e8\u5206WiFi\u7248\u672c\u7684\u5c0f\u7c73\u5e73\u677f\uff08\u4f8b\u5982\uff1a\u5c0f\u7c73\u5e73\u677f5 WiFi\u7248\u7b49\uff09\u65e0GPS\u786c\u4ef6\uff0c\u5373\u4f7f\u7528\u6237\u5f00\u542f\u4f4d\u7f6e\u670d\u52a1\uff0c\u5e94\u7528\u4e5f\u65e0\u6cd5\u83b7\u53d6\u5230GPS Provider\uff0c\u90e8\u5206\u4f9d\u8d56\u4e8eGPS\u4f4d\u7f6e\u670d\u52a1\u7684\u5e94\u7528\u53ef\u80fd\u4f1a\u63d0\u793a\u201c\u672a\u5f00\u542f\u4f4d\u7f6e\u670d\u52a1\u6216\u51fa\u73b0\u5176\u4ed6\u95ee\u9898\u201d\uff0c\u7528\u6237\u4f53\u9a8c\u8f83\u5dee\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,94,160],"tags":[3266,3378,5943,5944,5945,862,5942],"special":[67],"attr":[],"class_list":{"0":"post-12696","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appsj","7":"category-appjc","8":"category-appcs","9":"tag-demo","10":"tag-gps","12":"tag-location-proveders","13":"tag-network-provider","14":"tag-xiaomi","16":"special-xiaomikfpt","17":"entry"},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/comments?post=12696"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12696\/revisions"}],"predecessor-version":[{"id":12697,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/posts\/12696\/revisions\/12697"}],"wp:attachment":[{"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/media?parent=12696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/categories?post=12696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/tags?post=12696"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/special?post=12696"},{"taxonomy":"attr","embeddable":true,"href":"https:\/\/www.yimenapp.com\/kb-yimen\/wp-json\/wp\/v2\/attr?post=12696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}