Android emulator 无法从android中的GPS获取位置(不调用onLocationChanged)
我的问题是,我无法使用LocationManager类和LocationListener获取GPS坐标。也许如果我给你看我的代码,你就会明白。 这是我在OnCreate中调用的代码: 我有一个类MyLocationListener,它实现了类LocationListener 我可以通过在DDMS的Emulator控件中模拟位置来获得位置。所以我试着在我的真实手机上测试。当我把它安装在手机上时,虽然我打开了GPS和wifi,但它无法自动获取当前位置 我试着在我的真实手机上运行另一个谷歌地图应用程序,效果很好。 我不明白代码有什么问题…有人能帮我吗Android emulator 无法从android中的GPS获取位置(不调用onLocationChanged),android-emulator,windows-mobile-gps,Android Emulator,Windows Mobile Gps,我的问题是,我无法使用LocationManager类和LocationListener获取GPS坐标。也许如果我给你看我的代码,你就会明白。 这是我在OnCreate中调用的代码: 我有一个类MyLocationListener,它实现了类LocationListener 我可以通过在DDMS的Emulator控件中模拟位置来获得位置。所以我试着在我的真实手机上测试。当我把它安装在手机上时,虽然我打开了GPS和wifi,但它无法自动获取当前位置 我试着在我的真实手机上运行另一个谷歌地图应用程序
locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
currentLocListener = new MyLocationListener();
locMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, currentLocListener);
locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, currentLocListener);
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
String coordinates[] = {""+location.getLatitude(),""+location.getLongitude()};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint((int)(lat*1E6), (int)(lng*1E6));
mc.animateTo(p);
mc.setZoom(19);
MyMapOverlays marker = new MyMapOverlays(p);
List<Overlay> listofOverLays = mapview.getOverlays();
listofOverLays.clear();
listofOverLays.add(marker);
mapview.invalidate();
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "GPS is disabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "GPS is Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}