1

gps 機能を使用するアプリケーションを使用しています (Eclipse で AVD を使用)。このアプリケーションは、DDMS で座標を配置すると正常に動作しますが、前のポイント (20 ~ 30 m) に非常に近いポイントを挿入すると、onLocationChanged(Location loc)イベントは呼び出されません (ただし、アプリケーションはクラッシュしません。挿入するとそれほど近くない新しいポイント、イベントは正しく呼び出されます)。これはエミュレータの問題ですか?それとも方法による問題requestLocationUpdates(...)でしょうか?私のコードはこれです:

public class myActivity extends Activity 
{

    private TextView mytext;
    private LocationManager locmgr = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        GPSListener gpsListener=newGPSListener();
        mytext = (TextView) findViewById(R.id.mytext);

        //grab the location manager service
        locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locmgr.requestLocationUpdates(locmgr.GPS_PROVIDER, 10, 10, gpsListener);

        mytext.setText("waiting for location");
    }

    //Start a location listener
    private class GPSListener implements LocationListener
    {
        public void onLocationChanged(Location loc) 
        {
            //sets and displays the lat/long when a location is provided
            String latlong = "Lat: " + loc.getLatitude() + " Long: " + loc.getLongitude();   
            mytext.setText(latlong);
        }

    public void onProviderDisabled(String provider) 
    {

    }

    public void onProviderEnabled(String provider) 
    {

    }

    public void onStatusChanged(String provider, int status,
    Bundle extras) 
    {

    }
}
 }
4

2 に答える 2

1

requestLocationUpdates メソッドを呼び出すと、最小距離を変更できます。

locmgr.requestLocationUpdates(locmgr.GPS_PROVIDER, 10, 2, gpsListener);

これが説明です。

于 2013-09-12T09:26:29.357 に答える