0

我正在测试使用内置 Eclipse 工具将坐标发送到 Android 模拟器的选项。但它似乎没有收到它们。我有这个简单的代码:

public class Main extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MapView view = (MapView) findViewById(R.id.themap);
    view.setBuiltInZoomControls(true);

    final MapController mp = view.getController();

    LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    LocationListener listener = new LocationListener() {

        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onLocationChanged(final Location location) {
            // TODO Auto-generated method stub
            mp.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));

        }
    };
    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);

}



@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
}

我在 Manifest 中拥有 ACCESS_FINE_LOCATION 和 INTERNET 的权限。如果有人有任何解释,我将不胜感激。

4

2 回答 2

0

你加了吗

<uses-library android:name="com.google.android.maps" />

到清单中的应用程序标签?您还需要 Google 提供的 SDK 调试证书的 MD5 指纹才能接收 Google 地图数据。你可以在这里得到它。

尝试在 onLocationChanged 方法中放置一个断点,看看它是否在向模拟器发送位置命令时停止。当您还没有证书时,这也应该有效。

于 2012-05-19T12:06:46.113 回答
0

这对我有用。

监听器实现...

public class MyLocationListener implements LocationListener {
    public static final String TAG = "MyLocationListener";

    private Context context;

    public MyLocationListener(Context c) {
        this.context = c;
    }

public void onLocationChanged(android.location.Location location) {
        Log.d(TAG,"LocationChanged: Lat: "+location.getLatitude()+" Lng: "+location.getLongitude());
    }
}

用法...

MyLocationListener locationListener = new MyLocationListener(this);
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,locationListener);
于 2012-06-21T01:10:14.153 回答