{"id":56,"date":"2022-10-28T19:31:58","date_gmt":"2022-10-28T11:31:58","guid":{"rendered":"https:\/\/mianka.xyz\/?p=54"},"modified":"2022-10-28T19:33:05","modified_gmt":"2022-10-28T11:33:05","slug":"autojsgps","status":"publish","type":"post","link":"https:\/\/www.mianka.xyz\/?p=56","title":{"rendered":"Autojs\u83b7\u53d6GPS\u5b9a\u4f4d\u4fe1\u606f"},"content":{"rendered":"<p>\u8bb0\u5f97\u5148\u628aautojs\u7684\u201c\u5b9a\u4f4d\u6743\u9650\u201d\u7ed9\u5f00\u4e86\uff01\uff01\uff01\uff01<\/p>\n<pre class=\"prism-highlight prism-language-javascript\">console.show();\nimportClass(android.content.BroadcastReceiver);\nimportClass(android.content.Intent);\nimportClass(android.content.Context);\nimportClass(android.app.PendingIntent);\nimportClass(android.provider.Settings);\nimportClass(android.net.Uri);\nimportClass(android.content.IntentFilter);\nimportClass(android.location.LocationManager);\nimportClass(android.location.Location);\nimportClass(android.location.LocationListener);\nimportClass(android.location.Criteria);\n&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;\nfunction&nbsp;getLocation(){\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mLocationManager&nbsp;=context.getSystemService(Context.LOCATION_SERVICE);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;criteria&nbsp;=&nbsp;new&nbsp;Criteria();\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setAccuracy(Criteria.ACCURACY_FINE);&nbsp;\/\/\u5b9a\u4f4d\u7cbe\u5ea6:&nbsp;\u6700\u9ad8\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setAltitudeRequired(true);&nbsp;\/\/\u6d77\u62d4\u4fe1\u606f\uff1a\u4e0d\u9700\u8981\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setBearingRequired(true);&nbsp;\/\/\u65b9\u4f4d\u4fe1\u606f:&nbsp;\u4e0d\u9700\u8981\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setCostAllowed(true);&nbsp;&nbsp;\/\/\u662f\u5426\u5141\u8bb8\u4ed8\u8d39\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setPowerRequirement(Criteria.POWER_LOW);&nbsp;\/\/\u8017\u7535\u91cf:&nbsp;\u4f4e\u529f\u8017\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;provider&nbsp;=mLocationManager.getBestProvider(criteria,&nbsp;true);&nbsp;\/\/\u83b7\u53d6GPS\u4fe1\u606f\n&nbsp;&nbsp;&nbsp;&nbsp;log(provider);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;location&nbsp;=&nbsp;mLocationManager.getLastKnownLocation(provider);\n&nbsp;&nbsp;&nbsp;&nbsp;mLocationManager.requestLocationUpdates(provider,&nbsp;2000,&nbsp;5,&nbsp;locationListener);\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;location;\n}\n&nbsp;\nfunction&nbsp;openGPS(){\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;settingsIntent&nbsp;=&nbsp;new&nbsp;Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);\n&nbsp;&nbsp;&nbsp;&nbsp;settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n&nbsp;&nbsp;&nbsp;&nbsp;context.startActivity(settingsIntent);\n}\/\/\u6253\u5f00gps\n&nbsp;\nfunction&nbsp;gpsIsOpen(){\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;alm=context.getSystemService(Context.LOCATION_SERVICE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;bRet=true;\n&nbsp;&nbsp;&nbsp;&nbsp;if(!alm.isProviderEnabled(LocationManager.GPS_PROVIDER))\n&nbsp;&nbsp;&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;bRet&nbsp;=&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;bRet;\n}\/\/\u5224\u65adgps\u662f\u5426\u6253\u5f00\n&nbsp;\n&nbsp;\nif(!gpsIsOpen()){openGPS();}\nlocationListener=new&nbsp;LocationListener(){\n&nbsp;onLocationChanged(location){\n&nbsp;&nbsp;if(location!=null){\n&nbsp;&nbsp;&nbsp;log(&quot;\u7ef4\u5ea6:&quot;+location.getLatitude()+&quot;\\n\u7ecf\u5ea6:&quot;+location.getLongitude());\n&nbsp;&nbsp;}else{\n&nbsp;&nbsp;&nbsp;log(&quot;\u83b7\u53d6\u4e0d\u5230\u6570\u636e&quot;);\n&nbsp;&nbsp;}\n&nbsp;}\n};\n&nbsp;\nvar&nbsp;mLocation&nbsp;=&nbsp;getLocation();\nconsole.clear();\nlog(Object.keys(mLocation));\nlog(&quot;\u4f4d\u7f6e\u4fe1\u606f\uff1a&quot;+mLocation);\nlog(&quot;gps\u65f6\u95f4:&quot;+new&nbsp;Date(mLocation.time));\nlog(mLocation);<\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bb0\u5f97\u5148\u628aautojs\u7684\u201c\u5b9a\u4f4d\u6743\u9650\u201d\u7ed9\u5f00\u4e86\uff01\uff01\uff01\uff01<\/p>\n<pre class=\"prism-highlight prism-language-javascript\">console.show();\nimportClass(android.content.BroadcastReceiver);\nimportClass(android.content.Intent);\nimportClass(android.content.Context);\nimportClass(android.app.PendingIntent);\nimportClass(android.provider.Settings);\nimportClass(android.net.Uri);\nimportClass(android.content.IntentFilter);\nimportClass(android.location.LocationManager);\nimportClass(android.location.Location);\nimportClass(android.location.LocationListener);\nimportClass(android.location.Criteria);\n&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;\nfunction&nbsp;getLocation(){\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;mLocationManager&nbsp;=context.getSystemService(Context.LOCATION_SERVICE);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;criteria&nbsp;=&nbsp;new&nbsp;Criteria();\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setAccuracy(Criteria.ACCURACY_FINE);&nbsp;\/\/\u5b9a\u4f4d\u7cbe\u5ea6:&nbsp;\u6700\u9ad8\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setAltitudeRequired(true);&nbsp;\/\/\u6d77\u62d4\u4fe1\u606f\uff1a\u4e0d\u9700\u8981\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setBearingRequired(true);&nbsp;\/\/\u65b9\u4f4d\u4fe1\u606f:&nbsp;\u4e0d\u9700\u8981\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setCostAllowed(true);&nbsp;&nbsp;\/\/\u662f\u5426\u5141\u8bb8\u4ed8\u8d39\n&nbsp;&nbsp;&nbsp;&nbsp;criteria.setPowerRequirement(Criteria.POWER_LOW);&nbsp;\/\/\u8017\u7535\u91cf:&nbsp;\u4f4e\u529f\u8017\n&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;provider&nbsp;=mLocationManager.getBestProvider(criteria,&nbsp;true);&nbsp;\/\/\u83b7\u53d6GPS\u4fe1\u606f\n&nbsp;&nbsp;&nbsp;&nbsp;log(provider);\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;location&nbsp;=&nbsp;mLocationManager.getLastKnownLocation(provider);\n&nbsp;&nbsp;&nbsp;&nbsp;mLocationManager.requestLocationUpdates(provider,&nbsp;2000,&nbsp;5,&nbsp;locationListener);\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;location;\n}\n&nbsp;\nfunction&nbsp;openGPS(){\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;settingsIntent&nbsp;=&nbsp;new&nbsp;Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);\n&nbsp;&nbsp;&nbsp;&nbsp;settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n&nbsp;&nbsp;&nbsp;&nbsp;context.startActivity(settingsIntent);\n}\/\/\u6253\u5f00gps\n&nbsp;\nfunction&nbsp;gpsIsOpen(){\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;alm=context.getSystemService(Context.LOCATION_SERVICE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;bRet=true;\n&nbsp;&nbsp;&nbsp;&nbsp;if(!alm.isProviderEnabled(LocationManager.GPS_PROVIDER))\n&nbsp;&nbsp;&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;bRet&nbsp;=&nbsp;false;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;bRet;\n}\/\/\u5224\u65adgps\u662f\u5426\u6253\u5f00\n&nbsp;\n&nbsp;\nif(!gpsIsOpen()){openGPS();}\nlocationListener=new&nbsp;LocationListener(){\n&nbsp;onLocationChanged(location){\n&nbsp;&nbsp;if(location!=null){\n&nbsp;&nbsp;&nbsp;log(&quot;\u7ef4\u5ea6:&quot;+location.getLatitude()+&quot;\\n\u7ecf\u5ea6:&quot;+location.getLongitude());\n&nbsp;&nbsp;}else{\n&nbsp;&nbsp;&nbsp;log(&quot;\u83b7\u53d6\u4e0d\u5230\u6570\u636e&quot;);\n&nbsp;&nbsp;}\n&nbsp;}\n};\n&nbsp;\nvar&nbsp;mLocation&nbsp;=&nbsp;getLocation();\nconsole.clear();\nlog(Object.keys(mLocation));\nlog(&quot;\u4f4d\u7f6e\u4fe1\u606f\uff1a&quot;+mLocation);\nlog(&quot;gps\u65f6\u95f4:&quot;+new&nbsp;Date(mLocation.time));\nlog(mLocation);<\/pre>\n<p><!--autointro--><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[11],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-qianduan","tag-post-1776407685"],"_links":{"self":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=56"}],"version-history":[{"count":0,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mianka.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}