2013-05-01 27 views
3

我看着雷達例如城市的例子:AndEngine位置

http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/app/cityradar/CityRadarActivity.java?r=dea4a6fe72f983821ddbc287cfb90a8562f4b433

,我已經實現了ILocationListener並啓用了位置傳感器 並且也通過的onResume方法使位置傳感器:

@Override 
protected synchronized void onResume() 
{ 
    super.onResume(); 
    System.gc(); 

    final LocationSensorOptions locationSensorOptions = new LocationSensorOptions(); 
    locationSensorOptions.setAccuracy(Criteria.ACCURACY_COARSE); 
    locationSensorOptions.setMinimumTriggerTime(0); 
    locationSensorOptions.setMinimumTriggerDistance(0); 
    this.enableLocationSensor(this, locationSensorOptions); 
} 

,然後試圖上的位置獲得位置通過實現的方法改變

@Override 
public void onLocationChanged(Location plocation) { 
     this.mUserLocation = plocation; 
     curlng = mUserLocation.getLongitude(); 
     curlat = mUserLocation.getLatitude(); 


} 

但我只得到零,我有點困惑是否使用andengine中內置的位置傳感器或使用android原生位置傳感器?

回答

1

它使用Android位置傳感器。

還有,你應該檢查幾件事情:

  • 你有沒有設置在AndroidManifest.xml中的ACCESS_FINE_LOCATIONACCESS_COARSE_LOCATION權限?
  • 檢查您的設備上是否有GPS。即使打開了,也可能需要一段時間才能鎖定。

除非您發佈Logcat輸出,否則無法給出確切的答案。