Get the ANDROID position through WiFi

This symptom is often covered, but I did not find another problem, so here are the same standards…

I’m making a An application that successfully uses GPS when the device provides services. I have a test device with Android version 2.3.4. It does not have a SIM card, so GPS is not expected. However, it can get the location through Wifi in Google Maps. But my application cannot Get location on this device. On devices with services, I can get the same behavior by putting the device in airplane mode and then re-enabling Wifi.

In my app, I have a A GPS tracking class that implements LocationListener.

When the application starts, run the following code:

public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);

// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER );

// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
Log.d(LOG_TAG, "Requesting updates");
//TODO once tested, up the time below
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
// *** location is null here ***
if (location! = null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude() ;
}
}
}
}
}

} catch (Except ion e) {
e.printStackTrace();
}

return location;
}

See the note “location is null here This is the case for startup and subsequent calls after a few minutes.

None of these interface functions have been called:
onLocationChanged
onProviderEnabled
onProviderDisabled
onStatusChanged

Do I have any basic things? It seems that the location should be realized at least after waiting for a period of time. And, as mentioned above, Google Maps can only use wifi mode on both devices.

It turned out that the time to acquire the location was much longer than expected. I think about 2 minutes.

This symptom is often covered , But I did not find another problem, so here are the same standards…

I am making an application that successfully uses GPS when the device provides services. I have a version 2.3.4 A test device for Android. It does not have a SIM card, so GPS is not expected. However, it can get the location via Wifi in Google Maps. But my app cannot get the location on this device. On devices with services, I can get the location via Put the device in airplane mode and re-enable Wifi to get the same behavior.

In my application, I have a gps tracking class that implements LocationListener.

In the application At startup, run the following code:

public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService( LOCATION_SERVICE);

// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);

// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// First get location from Network Provider
if (isNetworkEnabled) {
Log .d(LOG_TAG, "Requesting updates");
//TODO once tested, up the time below
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager .NETWORK_PROVIDER);
// *** location is null here ***
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d(" GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}

return location;
}

See the note “location is null here”. This is the case for startup and subsequent calls in a few minutes.

None of these interface functions have been called:
onLocationChanged
onProviderEnabled
onProviderDisabled
onStatusChanged

Do I have any basic things? It seems that the location should be achieved at least after waiting for a period of time. And, as mentioned above, Google Maps can only use wifi mode on both devices.

It turned out that the time to acquire the location was much longer than expected. I think about 2 minutes.

Leave a Comment

Your email address will not be published.