android 海拔高度_Android:如何获取准确的海拔高度?

博客介绍了在Android中获取海拔高度的另一种方法,即解析NMEA字符串。通过为LocationManager创建NMEA字符串的侦听器并解析消息,可从$GPGGA语句中获取海拔修正高度数据,还可替换最后一个位置对象的高度或解析整个新位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

另一种方法是解析NMEA字符串。在$ GPGGA句话已经包含海拔修正高度数据。

因此,只需为LocationManager创建NMEA字符串的侦听器并解析消息:

private GpsStatus.NmeaListener mNmeaListener = new GpsStatus.NmeaListener() {

@Override

public void onNmeaReceived(long timestamp, String nmea) {

parseNmeaString(nmea);

}

};

public void registerLocationManager(Context context) {

mLocationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

mLocationManager.addNmeaListener(mNmeaListener);

}

private void parseNmeaString(String line) {

if (line.startsWith("$")) {

String[] tokens = line.split(",");

String type = tokens[0];

// Parse altitude above sea level, Detailed description of NMEA string here http://aprs.gids.nl/nmea/#gga

if (type.startsWith("$GPGGA")) {

if (!tokens[9].isEmpty()) {

mLastMslAltitude = Double.parseDouble(tokens[9]);

}

}

}

}

您可以替换通过位置侦听器收到的最后一个位置对象的高度,也可以通过NMEA解析整个新位置。

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:title="" app:navigationIcon="@drawable/back"> </androidx.appcompat.widget.Toolbar> <ImageView android:layout_width="match_parent" android:layout_height="180dp" android:src="@mipmap/picture_8" android:scaleType="centerCrop"/> <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:layout_margin="10dp" android:orientation="vertical" android:layout_height="wrap_content"> </androidx.appcompat.widget.LinearLayoutCompat> <TextView android:layout_marginTop="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="泰山,又名岱山、岱宗、岱岳、东岳、泰岳,为五岳之一,有“五岳之首”、“五岳独尊”、“天下第一山”之称,被中外学者称为“中国的奥林匹斯山”,位于山东省中部,隶属于泰安市,绵亘于泰安、济南、淄博三市之间,总面积25000公顷,主峰玉皇顶海拔约1545米"/> </androidx.appcompat.widget.LinearLayoutCompat> </RelativeLayout>
最新发布
06-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值