vivo手机定位海拔高度

vivo手机定位海拔高度,第1张

一般情况下,vivo手机可以通过定位功能获取当前的地理位置信息,但是如果要获取海拔高度,则需要满足一定条件。具体方法如下:

1 打开vivo手机的定位服务。进入设置-位置信息,确保定位服务已开启,并确认您已授权应用程序访问位置服务。

2 使用支持高程角度的应用程序。为了获取海拔高度,您需要使用支持高程角度的应用程序,如Google地图或高德地图等。进入应用程序后,打开位置服务和定位功能,然后等待应用程序定位您的位置。

3 确认位置信息显示。在Google地图或高德地图等应用程序中,您可以找到您的位置,并显示当前位置的海拔高度。

需要注意的是,vivo手机的高度数据可能不太准确,因为它是通过手机内置的气压计来计算的,而气压会受到许多因素的影响。如果需要获取更准确的海拔高度数据,建议使用专业的高度仪器。

手机的海拔功能是一种测量设备,它可以测量手机所处的高度,通常是以海拔米来表示的。它的原理是通过利用手机的GPS模块和气压传感器来测量。GPS模块可以接收卫星信号,计算出手机所处的经纬度和高度,而气压传感器可以检测到当前气压,从而计算出手机所处的海拔高度。海拔功能不仅可以帮助用户快速获取当前所处的高度,还可以帮助用户更加深入地了解当前所处的环境,例如气压、温度等。

一、LocationManager

LocationMangager,位置管理器。要想 *** 作定位相关设备,必须先定义个LocationManager。我们可以通过如下代码创建LocationManger对象。

LocationManger locationManager=(LocationManager)thisgetSystemService(ContextLOCATION_SERVICE);

二、LocationListener

LocationListener,位置监听,监听位置变化,监听设备开关与状态

private LocationListener locationListener=new LocationListener() {

/

位置信息变化时触发

/

public void onLocationChanged(Location location) {

updateView(location);

Logi(TAG, "时间:"+locationgetTime());

Logi(TAG, "经度:"+locationgetLongitude());

Logi(TAG, "纬度:"+locationgetLatitude());

Logi(TAG, "海拔:"+locationgetAltitude());

}

/

GPS状态变化时触发

/

public void onStatusChanged(String provider, int status, Bundle extras) {

switch (status) {

//GPS状态为可见时

case LocationProviderAVAILABLE:

Logi(TAG, "当前GPS状态为可见状态");

break;

//GPS状态为服务区外时

case LocationProviderOUT_OF_SERVICE:

Logi(TAG, "当前GPS状态为服务区外状态");

break;

//GPS状态为暂停服务时

case LocationProviderTEMPORARILY_UNAVAILABLE:

Logi(TAG, "当前GPS状态为暂停服务状态");

break;

}

}

/

GPS开启时触发

/

public void onProviderEnabled(String provider) {

Location location=lmgetLastKnownLocation(provider);

updateView(location);

}

/

GPS禁用时触发

/

public void onProviderDisabled(String provider) {

updateView(null);

}

};

三、Location

Location,位置信息,通过Location可以获取时间、经纬度、海拔等位置信息。上面采用locationListener里面的onLocationChanged()来获取location,下面讲述如何主动获取location。

Location location=locationManagergetLastKnownLocation(LocationManagerGPS_PROVIDER);

systemoutprintln("时间:"+locationgetTime());

systemoutprintln("经度:"+locationgetLongitude());

注意:Location location=new Location(LocationManagerGPS_PROVIDER)方式获取的location的各个参数值都是为0。

四、GpsStatusListener

GpsStatusListener ,GPS状态监听,包括GPS启动、停止、第一次定位、卫星变化等事件。

//状态监听

GpsStatusListener listener = new GpsStatusListener() {

public void onGpsStatusChanged(int event) {

switch (event) {

//第一次定位

case GpsStatusGPS_EVENT_FIRST_FIX:

Logi(TAG, "第一次定位");

break;

//卫星状态改变

case GpsStatusGPS_EVENT_SATELLITE_STATUS:

Logi(TAG, "卫星状态改变");

//获取当前状态

GpsStatus gpsStatus=lmgetGpsStatus(null);

//获取卫星颗数的默认最大值

int maxSatellites = gpsStatusgetMaxSatellites();

//创建一个迭代器保存所有卫星

Iterator<GpsSatellite> iters = gpsStatusgetSatellites()iterator();

int count = 0;

while (itershasNext() && count <= maxSatellites) {

GpsSatellite s = itersnext();

count++;

}

Systemoutprintln("搜索到:"+count+"颗卫星");

break;

//定位启动

case GpsStatusGPS_EVENT_STARTED:

Logi(TAG, "定位启动");

break;

//定位结束

case GpsStatusGPS_EVENT_STOPPED:

Logi(TAG, "定位结束");

break;

}

};

};

//绑定监听状态

lmaddGpsStatusListener(listener);

五、GpsStatus

GpsStatus,GPS状态信息,上面在卫星状态变化时,我们就用到了GpsStatus。

//实例化

GpsStatus gpsStatus = locationManagergetGpsStatus(null); // 获取当前状态

//获取默认最大卫星数

int maxSatellites = gpsStatusgetMaxSatellites();

//获取第一次定位时间(启动到第一次定位)

int costTime=gpsStatusgetTimeToFirstFix();

//获取卫星

Iterable<GpsSatellite> iterable=gpsStatusgetSatellites();

//一般再次转换成Iterator

Iterator<GpsSatellite> itrator=iterableiterator();

六、GpsSatellite

GpsSatellite,定位卫星,包含卫星的方位、高度、伪随机噪声码、信噪比等信息。

//获取卫星

Iterable<GpsSatellite> iterable=gpsStatusgetSatellites();

//再次转换成Iterator

Iterator<GpsSatellite> itrator=iterableiterator();

//通过遍历重新整理为ArrayList

ArrayList<GpsSatellite> satelliteList=new ArrayList<GpsSatellite>();

int count=0;

int maxSatellites=gpsStatusgetMaxSatellites();

while (itratorhasNext() && count <= maxSatellites) {

GpsSatellite satellite = itratornext();

satelliteListadd(satellite);

count++;

}

Systemoutprintln("总共搜索到"+count+"颗卫星");

//输出卫星信息

for(int i=0;i<satelliteListsize();i++){

//卫星的方位角,浮点型数据

Systemoutprintln(satelliteListget(i)getAzimuth());

//卫星的高度,浮点型数据

Systemoutprintln(satelliteListget(i)getElevation());

//卫星的伪随机噪声码,整形数据

Systemoutprintln(satelliteListget(i)getPrn());

//卫星的信噪比,浮点型数据

Systemoutprintln(satelliteListget(i)getSnr());

//卫星是否有年历表,布尔型数据

Systemoutprintln(satelliteListget(i)hasAlmanac());

//卫星是否有星历表,布尔型数据

Systemoutprintln(satelliteListget(i)hasEphemeris());

//卫星是否被用于近期的GPS修正计算

Systemoutprintln(satelliteListget(i)hasAlmanac());

}

为了便于理解,接下来模拟一个案例,如何在程序代码中使用GPS获取位置信息。

第一步:新建一个Android工程项目,命名为mygps,目录结构如下

第二步:修改mainxml布局文件,修改内容如下:

<xml version="10" encoding="utf-8">

<LinearLayout xmlns:android=">

第一步,申明权限。(50之后权限需要动态申请,具体代码和这个问题无关就不贴出来了)

<!--定位权限-->

<uses-permissionandroid:name=\"androidpermissionACCESS_FINE_LOCATION\"/>

<uses-permissionandroid:name=\"androidpermissionACCESS_COARSE_LOCATION\"/>

第二步通过LocationManager类获取位置信息,下面是一个封装好的工具类

CreatedbyDELLzhanghuirongon2019/3/15

获取当前位置信息

/

publicclassMyLocationUtil{

privatestaticStringprovider;

publicstaticLocationgetMyLocation(){

//获取当前位置信息

//获取定位服务

LocationManagerlocationManager=(LocationManager)MyAppgetContext()getSystemService(ContextLOCATION_SERVICE);

//获取当前可用的位置控制器

List<String>list=locationManagergetProviders(true);

if(listcontains(locationManagerGPS_PROVIDER)){

//GPS位置控制器

provider=locationManagerGPS_PROVIDER;//GPS定位

}elseif(listcontains(locationManagerNETWORK_PROVIDER)){

//网络位置控制器

provider=locationManagerNETWORK_PROVIDER;//网络定位

}

if(provider!=null){

if(ActivityCompatcheckSelfPermission(MyAppgetContext(),ManifestpermissionACCESS_FINE_LOCATION)!=PackageManagerPERMISSION_GRANTED&&ActivityCompatcheckSelfPermission(MyAppgetContext(),ManifestpermissionACCESS_COARSE_LOCATION)!=PackageManagerPERMISSION_GRANTED){

//TODO:Considercalling

//ActivityCompat#requestPermissions

//heretorequestthemissingpermissions,andthenoverriding

//publicvoidonRequestPermissionsResult(intrequestCode,String[]permissions,

//int[]grantResults)

//tohandlethecasewheretheusergrantsthepermissionSeethedocumentation

//forActivityCompat#requestPermissionsformoredetails

returnnull;

}

LocationlastKnownLocation=locationManagergetLastKnownLocation(provider);

returnlastKnownLocation;

}else{

ToastUtilsmakeText(\"请检查网络或GPS是否打开\");

}

returnnull;

}

}

第三步(其实到上一步这个问题已经解决了,这个算扩展吧)将位置信息转换成地址信息。

在高德或者百度地图开发者平台申请访问api许可。将第二步获取到的经纬度信息上传查询对应坐标信息。因为百度和高德用的不是同一个坐标系,查询时仔细看官方API。

直接通过安卓的原生接口获取一个gps的位置意义不是很大。这个数据在一定的坐标系上才有意义。建议去高德的开发平台注册个帐号,引入sdk来做,地理位置与地理位置解析的概念先了解下吧。

//第一步先获取LocationManager的对象LocationManagerGpsManager=(LocationManager)thisgetSystemService(ContextLOCATION_SERVICE);//通过LocationManager的对象来获取到Location的信息。Locationlocation=GpsManagergetLastKnownLocation(LocationManagerGPS_PROVIDER);//Location中经常用到的有以下几种:/locationgetAccuracy();精度locationgetAltitude();高度:海拔locationgetBearing();导向locationgetSpeed();速度locationgetLatitude();纬度locationgetLongitude();经度locationgetTime();UTC时间以毫秒计/注:需要添加使用权限的哦

以上就是关于vivo手机定位海拔高度全部的内容,包括:vivo手机定位海拔高度、手机有个海拔是干嘛的、android.location.Location 定位实例化等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9489817.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存