Android 将位置发送到仿真器
我正在测试使用内置Eclipse工具向Android Emulator发送坐标的选项。但它似乎没有收到坐标。我有以下简单代码:Android 将位置发送到仿真器,android,google-maps,android-emulator,Android,Google Maps,Android Emulator,我正在测试使用内置Eclipse工具向Android Emulator发送坐标的选项。但它似乎没有收到坐标。我有以下简单代码: public class Main extends MapActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceStat
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;
}
}
我有权访问清单中的位置和INTERNET。
如果有人有任何解释,我将不胜感激 您添加了什么
<uses-library android:name="com.google.android.maps" />
到清单中的应用程序标记?
您还需要来自Google的SDK调试证书的MD5指纹来接收Google地图数据。你可以得到它
尝试在onLocationChanged方法中放置一个断点,并查看它在向仿真器发送location命令时是否停止。当您还没有证书时,这也应该有效。这对我来说很有效
侦听器实现
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);
我不想给出这个笼统的答案,但是,如果它不起作用,那么您在仿真器方面就做错了。这可能不在你的代码中。还有什么可能是错误的呢?不幸的是,我能给你的最好建议是研究应该如何做到这一点,并找出你偏离它的地方。此外,google&SO搜索将提供大量信息。它似乎不会停止在onLocationChanged中…你知道为什么吗?你为模拟器添加了gps支持吗?转到avd管理器并单击avd上的编辑。然后在“硬件”部分添加gps支持条目。当您向模拟器发送位置数据时,您应该会在通知栏中看到gps图标。我看到了该图标,但位置没有改变:(