My code to obtain GPS coordinate works perfect in HTC cells. But I
find it doesn't work in Moto Droid. I debug it and find eveything
seems fine. But the coordinate never obtained. Please read my code
first:
/////////// defining listener
LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle
extras) {
}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onLocationChanged(Location location) {
stateGPS = PR.Types.SERVICE_ACTION_STATE_UPDATED;
currentPosition.latitude = location.getLatitude();
currentPosition.longitude = location.getLongitude();
locationManager.removeUpdates(locationListener);
}
};
.....
//////////updating location information
boolean gpsEnabled = false;
if
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
new Handler(getMainLooper()).post(new Runnable() {
public void run() {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, locationListener);
}
});
gpsEnabled = true;
}
if
(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
new Handler(getMainLooper()).post(new Runnable() {
public void run() {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0, 0, locationListener);
}
});
gpsEnabled = true;
}
.....
//////////////fetching coordinate
Location l = null;
if
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
l =
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
if (l == null &&
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
l =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
locationManager.removeUpdates(locationListener);
if (l == null) {
//gps unknown
stateGPS =
PR.Types.SERVICE_ACTION_STATE_OTHER;
return;
} else {
currentPosition.latitude =
l.getLatitude();
currentPosition.longitude =
l.getLongitude();
stateGPS =
PR.Types.SERVICE_ACTION_STATE_UPDATED;
}
....
No error message, No fatal return. Every things invoked well, but
onLocationChanged() never be run, getLastKnownLocation() always return
null ----- No GPS information get at all. I check all the settings.
GPS device is opened and every thing is OK. The same code works in my
HTC magic, G2.
Please help me. Thank you!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en