2011-02-16 140 views
0

你好,我一直在使用本指南确定locationof用户:http://developer.android.com/guide/topics/location/obtaining-user-location.html获取与GPS /网络的Android MapView的用户当前位置

和我当前的代码看起来是这样的:

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

    LocationListener locationListener = new LocationListener() { 
     public void onLocationChanged(Location location) { 
      test = new GeoPoint((int)location.getLatitude()*1000000, (int)location.getAltitude()*1000000); 
      mapController.animateTo(test); 
     } 

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

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

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

     } 
    }; 
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 
} 
只有

我当我使用此活动时,会收到错误并关闭应用程序。

感谢帮助

+1

你可以发布你的logcat痕迹吗? – Reno 2011-02-16 10:27:20

+0

请发布错误日志 – Mathew 2011-02-16 11:04:36

回答

0

我解决了这个问题,我没有实例mapContoller:>。但我现在有另一个问题。我将在另一个问题中发帖。

0

请确认您已经获分配以下权限到你的manifest文件

ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION

0

我猜你是在设备

尝试执行这段代码此设备上

设置 - >位置 - >使用GPS

设置 - >应用程序设置 - >开发 - >允许模拟地点