Not getting Lat/Long on Emulator as well as on device
i am done code for getting current lat/long as follow but i always get null from lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); method.
i have tried by 2 ways.
the code is below.
first way,
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null)
{
lat = location.getLatitude();
开发者_开发问答 lon = location.getLongitude();
}
and second way,
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Log.d("GPS_PROVIDER","GPS_PROVIDER = " + lm.isProviderEnabled(LocationManager.GPS_PROVIDER));
Log.d("NW_PROVIDER","NW_PROVIDER = " + lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListenerAdapter()
{
@Override
public void onLocationChanged(Location location)
{
if(location != null)
{
lat = location.getLatitude();
lon = location.getLongitude();
}
}
});
LocationListenerAdapter class is implements the method of LocationListener interface and i keep all method blank i.e no code written into that methods.
i also use gpx and kml file for emulator to change lat/long but i didn't get yet. can any one provide best answer.
Thanks in advance.
精彩评论