GPS定期更换

时间:2011-05-16 08:59:19

标签: android

我的Gps代码使用android没有定期更改,尽管我做了更改位置方法这里是我的代码,我想知道为什么我不改变一些它保持相同的lat和长时间说长距离说10米然后在这里更改是代码

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() ;

        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;
          }

           }

那么我还需要添加什么方法!!

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>

请求位置更新在此处是oncreate方法

enter code here

    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, mlocListener);

1 个答案:

答案 0 :(得分:0)

  

通知的频率或新的   可以使用。来控制位置   minTime和minDistance参数。如果   minTime大于0,即   LocationManager可能会休息   for minTime毫秒之间   位置更新以节省电力。如果   minDistance大于0,a   位置只会在广播时播出   设备按minDistance米移动。至   经常获取通知   可能,将两个参数都设置为0。

从android文档中尽可能频繁地请求通知的代码。您声称看到的任何异常行为都是由于使用了GPS芯片组。它们并不那么准确。你应该容忍10到50米的误差。