问题
How do I programmatically find direction on a blackberry using GPS?
回答1:
With GPS, the minimum resolution is aroud 3 meters. If you take consecutive GPS readings and look for significant changes in a given direction, it will give you a rough estimate of the direction of travel, and thus a probable direction the person is facing.
This is not nearly as good as having a magnetic compass, which none of the Blackberries (Blackberrys?) on the market currently have.
Some GPS systems have two GPS receivers placed beside each other in a known orientation. They can calculate which direction the unit is facing based on comparing two GPS readings. They call it a GPS compass. Also, these systems are too bulky to be included in a phone at this point.
You can use the Blackberry API to find the GPS information including the course made good heading (getCourse method). It will give you a compass reading with 0.00 being North.
回答2:
GPS data can not give you direction, it only gives you positions. If you have two positions (such as where you were 1 second ago, and where you are now), most implementations, including the Blackberry, will give you the bearing (direction) from one point to the other.
Android devices, and IIRC the iPHone 3Gs, with digital magnetic compasses can give you direction. I don't believe there are any Blackberries equipped with compasses yet.
回答3:
The GPS API in java micro that the Blackberry uses will supply you with the direction the phone is heading. Here is a snippet of a GPS class that retrieves most of the basic GPS info:
/**
* This will start the GPS
*/
public GPS() {
// Start getting GPS data
if (currentLocation()) {
// This is going to start to try and get me some data!
}
}
private boolean currentLocation() {
boolean retval = true;
try {
LocationProvider lp = LocationProvider.getInstance(null);
if (lp != null) {
lp.setLocationListener(new LocationListenerImpl(), interval, 1, 1);
} else {
// GPS is not supported, that sucks!
// Here you may want to use UiApplication.getUiApplication() and post a Dialog box saying that it does not work
retval = false;
}
} catch (LocationException e) {
System.out.println("Error: " + e.toString());
}
return retval;
}
private class LocationListenerImpl implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
if (location.isValid()) {
heading = location.getCourse();
longitude = location.getQualifiedCoordinates().getLongitude();
latitude = location.getQualifiedCoordinates().getLatitude();
altitude = location.getQualifiedCoordinates().getAltitude();
speed = location.getSpeed();
// This is to get the Number of Satellites
String NMEA_MIME = "application/X-jsr179-location-nmea";
satCountStr = location.getExtraInfo("satellites");
if (satCountStr == null) {
satCountStr = location.getExtraInfo(NMEA_MIME);
}
// this is to get the accuracy of the GPS Cords
QualifiedCoordinates qc = location.getQualifiedCoordinates();
accuracy = qc.getHorizontalAccuracy();
}
}
public void providerStateChanged(LocationProvider provider, int newState) {
// no-op
}
}
来源:https://stackoverflow.com/questions/2362025/how-do-i-programmatically-find-direction-on-a-blackberry