我正在使用一个使用 gps 功能的应用程序(在 Eclipse 上使用 AVD)。当我用 DDMS 放置坐标时,此应用程序工作正常,但如果我插入一个非常接近前一个点 (20-30m) 的点,则不会调用 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)
{
}
}
}
最佳答案
您可以在调用 requestLocationUpdates 方法时更改最小距离。
locmgr.requestLocationUpdates(locmgr.GPS_PROVIDER, 10, 2, gpsListener);
Here是解释。
关于java - GPS 不适用于短距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18760195/