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

Autojs获取GPS定位信息

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

记得先把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版权f8防采集https://mianka.xyz

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

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

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

标签: 前端
分享给朋友:

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

autojs强制关闭APP详解

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

layui框架引入css文件不报错也不生效

layui框架引入css文件不报错也不生效link加入rel=“stylesheet” type=“text/css” 属性即可实例<link type="text/css" rel="stylesheet" href=&q...

jquery如何获取最后一个元素

jquery如何获取最后一个元素获取最后一个元素,并将文字设置为红色$(document).ready(function(){     $(p).last().css(color,red); });相关扩展:使用first()方法获取第一个元素#获取第一个...

jquery获取元素有两个,怎么获取第二个的属性名

如果你有两个相同类型的且具有相同类名或ID的元素,你可以使用jQuery的.eq()方法来获取第二个元素的属性名。这个方法返回指定元素的属性名。例如,假设你有两个div元素,它们都有class="myDiv",你可以这样获取第二个元素的class属性名:$('.myDiv...

h5页面怎么点击弹出独立窗口的方式展现

在H5页面中,可以使用JavaScript代码实现点击链接弹出独立窗口的功能。具体实现方法如下:在H5页面中添加一个链接元素,例如:<a href="#" onclick="openNewWindow()">点击这里弹出独立窗口...

怎么实现网页某个元素进入f11全屏模式

要实现网页某个元素进入全屏模式,你可以使用JavaScript的`requestFullscreen`方法。这个方法需要一个DOM元素作为参数,所以你需要选择一个元素来进入全屏模式。以下是一个简单的示例,当用户点击一个按钮时,会将页面上的一个`<div>`元素设置为全屏模式:<!D...