I'm currently using GPS only to get current location of the user to return certain results. As in Belgium, if you're inside, most of the time you can't get GPS-connection. So I want to get the current location with the wifi-connection.
I've found this example: get the current location (gps/wifi) But
I'm not sure which lines tell the device which connection to choose. I'm guessing it's this one: String provider = myLocationManager.getBestProvider(criteria,true);
That I've to add to my code.
When I check what's inside of this, I always get a null-value, I don't quite understand why.
My code looks currently like this:
public void getOwnLngLat(){
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
final LocationListener locationListener = new LocationListener(){
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
longitude="" + location.getLongitude();
latitude="" + location.getLatitude();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
};
locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), 2000, 10, locationListener);
}