Reputation: 1
I have a problem with the following code. I dont have GPS/ WIFI/ 3G kept "on" in my phone. I want to find the user location just from the network_provider but due to some reason it gives the latitude and longitude as 0.0 and 0.0 on the phone. Please help. My code is as follows:
LocationManager mlocManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
TextView txt=(TextView)findViewById(R.id.coordinate);
txt.setText(latid+","+longid+","+accu+"m "+provider);
and the requestLocationUpdates is as follows:
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged (Location loc)
{
latid=loc.getLatitude();
longid=loc.getLongitude();
accu=loc.getAccuracy();
TextView txt=(TextView)findViewById(R.id.coordinate);
txt.setText(latid+","+longid+","+accu+"m");
Toast.makeText (getApplicationContext(),"Entered function",Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled (String provider)
{
Toast.makeText (getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled (String provider)
{
Toast.makeText (getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT) .show();
}
@Override
public void onStatusChanged (String provider, int status, Bundle extras)
{
;
}
}/* End of Class MyLocationListener */
I wanted to know why i was getting all the outputs as 0.0 and 0.0 for lat and long. One more thing I have noticed, if i connect to my home WIFI then this gets a fix for my latitude and longitude. I want to know why it is not getting a fix without WIFI/3G/GPS on ! Any help will be appreciated..
Upvotes: 0
Views: 1588
Reputation: 13
you got 0.0 0.0,
it's because Geopoint turns latitude and Longitude into 1000000 times than it used to be.
If there is anything wrong with your gps 3g of wifi, it will pop out exception instead of get 0.0,0.0.
So, if you are about to assign a pair of la,long to geoPoint object, please remind youself with
location.latitude's value * 1000000 = Geopoint.latitude's value
location.longitude's value * 1000000 = Geopoint.longitude's value
**
The la/long of your current location is based on wifi device's approximation, and it's not that sensitive to sense you move within your house. So that's why you got a fix la/long.
Upvotes: 1
Reputation: 10039
The Location Provider needs to have either the 3G / Wifi /2G-Edge or GPS on to get a location fix.
http://developer.android.com/guide/topics/location/obtaining-user-location.html should give you more information.
Upvotes: 2