当前位置:首页 > 前端 > 正文内容

Autojs获取GPS定位信息

zhangsir3年前 (2022-10-28)前端402

记得先把autojs的“定位权限”给开了!!!!

console.show();
importClass(android.content.BroadcastReceiver);
importClass(android.content.Intent);
importClass(android.content.Context);
importClass(android.app.PendingIntent);
importClass(android.provider.Settings);
importClass(android.net.Uri);
importClass(android.content.IntentFilter);
importClass(android.location.LocationManager);
importClass(android.location.Location);
importClass(android.location.LocationListener);
importClass(android.location.Criteria);
 
    
function getLocation(){
    var mLocationManager =context.getSystemService(Context.LOCATION_SERVICE);
    var criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE); //定位精度: 最高
    criteria.setAltitudeRequired(true); //海拔信息:不需要
    criteria.setBearingRequired(true); //方位信息: 不需要
    criteria.setCostAllowed(true);  //是否允许付费
    criteria.setPowerRequirement(Criteria.POWER_LOW); //耗电量: 低功耗
    
    var provider =mLocationManager.getBestProvider(criteria, true); //获取GPS信息
    log(provider);
    var location = mLocationManager.getLastKnownLocation(provider);
    mLocationManager.requestLocationUpdates(provider, 2000, 5, locationListener);
    return location;
}
 
function openGPS(){
    var settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(settingsIntent);
}//打开gps
 
function gpsIsOpen(){
    var alm=context.getSystemService(Context.LOCATION_SERVICE);     
    var bRet=true;
    if(!alm.isProviderEnabled(LocationManager.GPS_PROVIDER))
    {
    bRet = false;
    }
    return bRet;
}//判断gps是否打开
 
 
if(!gpsIsOpen()){openGPS();}
locationListener=new LocationListener(){
 onLocationChanged(location){
  if(location!=null){
   log("维度:"+location.getLatitude()+"\n经度:"+location.getLongitude());
  }else{
   log("获取不到数据");
  }
 }
};
 
var mLocation = getLocation();
console.clear();
log(Object.keys(mLocation));
log("位置信息:"+mLocation);
log("gps时间:"+new Date(mLocation.time));
log(mLocation);


zhangsir版权f2防采集https://mianka.xyz

扫描二维码推送至手机访问。

版权声明:本文由zhangsir or zhangmaam发布,如需转载请注明出处。

本文链接:https://www.mianka.xyz/post/54.html

标签: 前端
分享给朋友:

“Autojs获取GPS定位信息” 的相关文章

ajax库Axios的使用方法

axios简介Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。axios的基本使用如何引入axios可以通过npm安装来进行使用npm install axio也可以使用 bower进行安装,然后在页面中进行引入:bower&nbs...

微信小程序引入echarts不显示 也不报错

微信小程序引入echarts不显示 也不报错1.在开发者工具上没有显示你需要给ceharts组件一个高度和宽度style="width: 100%; height: 100%;"2.给了高度和宽度还是没有显示你需要给ceharts标签外面的view加...

css如何设置input聚焦时的样式

input的聚焦时的样式怎么设置呢?input:focus-visible {   background-color: red; }这样应该就行了。...

h5 input 设置必填项

html5新增了一个required属性,可以使用这个属性对文本框设置必填项,直接在input文本框上添加required即可 。例如:<input type="text" name="name" placeholder=&...

autojs强制关闭APP详解

// 测试手机为红米note10 pro,autojsPro版本8.8.22-common killApp("微信"); function killApp(appName) {//填写包名或app名称都可以   &...

箭头函数的写法与定义与特点

箭头函数是一种JavaScript函数的语法简写形式。它是ES6(ECMAScript 2015)中的一个新特性,也称为Lambda表达式。箭头函数使用箭头(=>)来定义函数,它的基本语法格式如下:(parameters) => { statements&n...