Display the NMEA sentence?
Any one help to display the NMEA sentence like $GPRMC ..... I am using the below code:
public class SampleNMEA extends Activity implements LocationListener, GpsStatus.Listener,GpsStatus.NmeaListener{
LocationManager lm;
TextView output;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
output = (TextView)findViewById(R.id.out);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);
final Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
output.append("\nBelow Data is about the your location:");
output.append("\n\n\nLatit:"+location.getLatitude());
output.append("\n\nLongitude:"+location.getLongitude());
output.append("\n\nTime: "+location.getTime());
}
public void onLocationChanged(Location location)
{
output.append("\n\n\nLatitude:"+location.getLatitude());
output.append("\n\nLongitude:"+location.getLongitude());
output.append("\n\nTime: "+location.getTime());
}
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2)
{
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);
final Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
output.append("\n\n\nLatitude:"+location.getLatitude());
output.append("\n\nLongitude:"+location.getLongitude());
outpu开发者_运维问答t.append("\n\nTime: "+location.getTime());
}
public void onGpsStatusChanged(int event)
{
}
public void onNmeaReceived(long timestamp, String nmea)
{
output.append("NMEA Sentence: "+nmea);
}
}
Any one help I added permissions in manifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
Change your provider to GPS_PROVIDER.
You can get the nmea sentence by Gps provider.
Change this line
**lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);**
to
**lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000,10,this);**
Now check in onNmeaReceived() method.
Just add a NmeaListener
public class SampleNMEA extends Activity implements LocationListener, GpsStatus.Listener,GpsStatus.NmeaListener{
LocationManager lm;
TextView output;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
output = (TextView)findViewById(R.id.out);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000,10,this);
final Location location=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
output.append("\nBelow Data is about the your location:");
output.append("\n\n\nLatit:"+location.getLatitude());
output.append("\n\nLongitude:"+location.getLongitude());
output.append("\n\nTime: "+location.getTime());
//add listener here
lm.AddNmeaListener(this);
}
I have Samsung Galaxy Spica and yes, it doesn't work. However, I've installed 'ultra gps logger' (link) and NMEA data is correctly read. Perhaps author of this tool used different solution for reading NMEA which means that is possible.
Are you calling addNmeaListener(GpsStatus.NmeaListener)
to set that class as a listener? If not, you should!
To do so, call it like lm.addNmeaListener(this);
.
Good luck & Regards
The conclusion being reached in this discussion here, is that NMEA doesn't work on some phones (the onNmeaReceived event never fires). ...but would love to be corrected on this.
If fakeGps is in list of installed apps, be sure to delete it and restart device in order to start receiving Nmea info. You can install free Nmea Info monitor from play market to test Nmea receiver on your device.
精彩评论