2012-07-31 42 views
0

我從使用mylocation類的GPS提供商獲取數據。代碼是這樣的:Android mapview的地點差異模擬器和設備

MyLocation.LocationResult locationResult = new MyLocation.LocationResult() { 
     @Override 
     public void gotLocation(Location location) { 
      //Got the location! 

      // for phone 
      //currentLocation = new GeoPoint((int) (location.getLatitude() * 1000000), 
      // (int) (location.getLongitude() * 1000000)); 

      // for emulator 
      currentLocation = new GeoPoint((int) (location.getLatitude()), 
        (int) (location.getLongitude())); 

      doSomething(); 

     } 
    }; 
    MyLocation myLocation = new MyLocation(); 
    myLocation.getLocation(this, locationResult); 

當我在模擬器(2.3.3)中使用應用程序時,它顯示正確的位置而不會乘以任何東西。

但是當我使用它在一個設備(4.0)lat和lon需要乘以1000000.我無法找到原因。我不認爲它是因爲android的版本。任何人有任何想法?

回答

0

因爲MapView的單位使用了microdegress,所以你需要乘以1e6。否則,你出現在非洲海岸 - 基本上LAT長大約0,0

從上GeoPoint的文檔:

,不可變的類代表一對緯度和經度,存儲爲整數微度。

不知道爲什麼模擬器工作 - 它不應該。

+0

我按照你的說法試過,但它不能在模擬器中工作。如果設備沒有問題,如果它只在模擬器上出現問題,那對我來說就沒有問題。有沒有可能在每個設備上表現出不同的表現?例如對於android 2.3和4.0? – eluleci 2012-07-31 18:20:13

+0

不應該根據文檔 – Kaediil 2012-07-31 18:21:52

相關問題