Hi,
I am developing a GPS based application, and for my
application I need to get the current location, and also need to
update the UI as and when the location changes. So for that I am using
Location Manager and location listener package as follows,
public class HelloMapViewSec extends MapActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
myLocationListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
myLocationListener);
Location myLocation = lm.getLastKnownLocation("network");
//using
"gps" returned NULL
if(myLocation != null)
{
lat = myLocation.getLatitude() * 1E6;
lng = myLocation.getLongitude() * 1E6;
GeoPoint point = new
GeoPoint(lat.intValue(),lng.intValue());
//And had an overlay to point in MapView
}
}
//MyLocationListener Class defined for instantiating a location
listener
private class MyLocationListener implements
LocationListener
{
public void onLocationChanged(Location loc)
{
if (loc != null)
{
Toast.makeText(getBaseContext(),
"Location changed : Lat: " +
loc.getLatitude() +
" Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
}
}
public void onProviderDisabled(String
provider) {
// TODO Auto-generated method stub
System.out.println("GPS : Provider Disabled"
+ provider);
}
public void onProviderEnabled(String provider)
{
// TODO Auto-generated method stub
System.out.println("GPS : Provider Enabled" +
provider);
}
public void onStatusChanged(String provider,
int status,
Bundle extras) {
// TODO Auto-generated method stub
System.out.println("GPS : Status Changed to "
+ provider + "[" + status + "]");
}
}
}
I am able to get the current user details using the above code, but I
am not able to see the LocationListener's onLocationChanged()
functionality getting called within a travel of 10/100m. I have tried
by chaing the minDistance parameter of lm.requestLocationUpdates()
from 10 to 100, but still I dont see any quick response. I need a call
to LocationListener's onLocationChanged() functionality within 10/100m
so that I can do speed/distance calculations.
On further analysis I saw that the onLocationChanged() will be called
on a 500m change only. So is there any alternate method/means for
calculating the speed/distance travelled by user?
--
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