我在抨击android本地化,并已经想出了如何接收NMEA数据。不幸的是,结果似乎非常混乱。我只需要GPRMC的句子,但得到GPGGA,GPVTG等返回。有什么办法来控制onNmeaReceived()函数吗?Android位置:来自onNmeaReceived()的混沌结果
public class TrackingService extends Service {
private Intent broadcastIntent = new Intent("com.example.locationlogger.TestBroadcastReceiver");
private LocationManager lm;
private LocationListener ll = new LocationListener(){
//sample listener...
};
GpsStatus.NmeaListener nl = new GpsStatus.NmeaListener() {
@Override
public void onNmeaReceived(long timestamp, String nmea) {
/*
* Broadcast a message..
*/
broadcastIntent.putExtra("TESTVAR", "Received some nmea strings: " + nmea);
sendBroadcast(broadcastIntent);
}
};
@Override
public void onCreate() {
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
@Override
public void onStart(Intent intent, int startId) {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval * 1000, 0, ll);
lm.addNmeaListener(nl);
}
}
收到的句子往往是无效的吗?通过我的答案中的“过滤器”,我在考虑更多'sentence.startsWith(“$ GPRMC”);':)无论如何,肯定是一个有用的正则表达式! – 2010-08-04 18:31:13
如果使用我的应用程序,请使用requestLocationUpdates(..)“激活”手机中的GPS设备,然后添加NmeaListener。实际上,NmeaListner在初始化时会立即产生输出(无坐标的句子),并且在处理时遇到一些无效的句子。这就是完整正则表达式解决方案的原因。 – 2010-08-04 19:47:48