My Gps Code using android didnt change periodically despite i made changelocation method here is my code and i want to know why i doesn't change some times it keep same lat and long for long time say for distance 10 meters then change here is code
enter code here
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
GeoPoint point = new GeoPoint((int) (loc.getLatitude() * 1E6),
(int) (loc.getLongitude() * 1E6));
String Text = "My current location is: " +
"Latitud =" + loc.getLatitude()+
"Longitud =" +loc.getLongitude() ;
开发者_Go百科 Toast.makeText(getApplicationContext(),
Text,
Toast.LENGTH_SHORT).show();
}
}
private Resources getResources() {
// TODO Auto-generated method stub
return null;
}
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Disabled",
Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(),
"Gps Enabled",
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
protected boolean isRouteDisplayed() {
return false;
}
}/* End of Class MyLocationListener */
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
So what method i need also to add !!
enter code here
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".tryanabtry"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
the request location update is here it is on the oncreate method
enter code here
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, mlocListener);
The frequency of notification or new locations may be controlled using the minTime and minDistance parameters. If minTime is greater than 0, the LocationManager could potentially rest for minTime milliseconds between location updates to conserve power. If minDistance is greater than 0, a location will only be broadcast if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
From the android documentation your code request for notifications as frequently as possible. Any abnormal behavior that you claim to be seeing is due the the GPS chipset used. They are not so accurate. You should tolerate an error of 10 to 50 meters.
精彩评论