这是我的代码。我将 eclipse 与 avd 一起使用,并将其发送到我想要的坐标。我看到如果使用 API 7 或更高版本的 avd,我的应用程序工作正常,但如果我使用 API 3 的 avd,它只接受 3 个点,然后停止接受其他坐标(我仍然不知道是否有与 api 4-5-6 有同样的问题,因为我现在正在尝试)。编辑:API 4 没问题。
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)
{
}
}
}