2012-06-04 45 views
1

我正在使用mapView和LocationManager創建一個小的Android應用程序。 我的LocationManager應偵聽位置並通知我的位置是否在用戶定義的容差範圍內發生變化。 如果我的LocationManager注意到一個位置發生變化,它應該發送一條短信。使用locationMangager獲取錯誤的gps位置android

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, Float.parseFloat(txtToleranz.getText().toString()), this); 

在這裏,我不知道,如果方法requestLocationUpdates需要始終文本字段或僅給定初始值的當前值...?

另外我的應用程序應該顯示我在mapView中的位置,但是位置完全錯誤...爲什麼?我正在真實設備上運行我的應用程序。

   double lat = location.getLatitude(); 
      double lng = location.getLongitude(); 

      String currentLocation = " Lat: " + lat + " Lng: " + lng + " Tol: " + Toleranz; 
      point = new GeoPoint((int) lat * 1000000, (int) lng * 1000000); 
      mapController.animateTo(point); 
      mapController.setZoom(15); 
      System.out.println(currentLocation); 

謝謝任何​​幫助! 最好的問候丹尼爾

回答

0

根據this SO postGeoPoint可能構造不正確,這可能會導致一個不正確的位置。至於LocationManagerrequestLocationUpdates方法只能運行一次,這意味着該方法運行時取值爲EditText's,除非您告訴它,否則它不會更新。在LocationManager類中可能有一種方法可以做到這一點。

編輯

忽略有關GeoPoint的一部分,在進一步閱讀你是在乘以1000000

+0

乘以你的長/ LAT正確的你有一個想法如何與GeoPoint的更好的工作或類似的東西這個? – Daniel05

+0

爲什麼你不把lat/long傳遞給用戶地圖應用程序並獲取它來顯示它?我用類似峯會'意圖地圖=新意圖(android.content.Intent.ACTION_VIEW, \t \t \t \t \t Uri.parse( 「地理:0,0 Q =」 +緯度+」, 「+經度+」(你的地點)」)); \t \t \t \t \t maps.setClassName(「com.google.android.apps.maps」,「com.google.android.maps.MapsActivity」); \t \t \t \t \t startActivity(maps);'before。它運作良好。 – dotty

+0

我應該在哪裏實施?哪種方法? – Daniel05