2012-01-02 116 views
0

我正在嘗試查找緯度和經度的代碼,但需要大量時間才能給出座標,或者根本沒有給出座標,可能是什麼問題。我正在三星Galaxy選項卡上嘗試我的代碼。android gps設備獲取緯度和經度所用的時間

LocationManager mlocManager; 
double lat,lng; 
LocationListener mlocListener = new MyLocationListener(); 

我稱之爲的onCreate下面的代碼()方法

mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 

監聽MyLocationListener類代碼如下

public class MyLocationListener implements LocationListener 

     { 




     @Override 
     public void onLocationChanged(Location loc){ 

     loc.getLatitude(); 

     loc.getLongitude(); 

     String Text = "My current location is: " + "Latitude = " + loc.getLatitude() + "Longitude = " + loc.getLongitude(); 
     String latLongString = ""; 
     if (loc != null) { 
      lat = loc.getLatitude(); 
      lng = loc.getLongitude(); 
      latLongString = "Lat:" + lat + "\nLong:" + lng; 
      TextView myLocationText = (TextView)findViewById(R.id.FindUsTextView); 
      myLocationText.setText("Your Current Position is:\n" + latLongString); 
      System.out.println(latLongString); 

     } 
     /* findUsProgressbarField.setVisibility(View.INVISIBLE);*/ 
     Toast.makeText(FindUs.this, Text, Toast.LENGTH_SHORT).show(); 
     mlocManager.removeUpdates(mlocListener); 

     } 

     @Override 

     public void onProviderDisabled(String provider){ 

     Toast.makeText(getApplicationContext(),"Gps Disabled, Please Enable the GPS", Toast.LENGTH_SHORT).show(); 

     } 

     @Override 

     public void onProviderEnabled(String provider){ 

     Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show(); 

     } 

     @Override 

     public void onStatusChanged(String provider, int status, Bundle extras){ 

     } 



     } 
     @Override 
     protected void onDestroy() { 
     super.onDestroy(); 
     if (mlocManager != null) { 
      mlocManager.removeUpdates(mlocListener); 
      mlocManager = null; 
     } 
     } 

可能是問題,任何指針或有我不考慮什麼一些觀點。 期待您的回覆。 謝謝。

+2

聽起來像是「按設計」工作。公司並不總是可用。第一次獲得他們是昂貴的(及時)。 – 2012-01-02 13:05:33

回答

1

如果你像大多數人一樣在裏面進行測試的時候正在開發中,這是相當標準的。 GPS喜歡看天空。試着坐在一個很好的大窗戶旁邊。它幫助到我。

1

如果Galaxy Tab的具有A-GPS(輔助GPS)capabilty,也就是說,如果有amonst設備的「位置和Secuirity」「使用無線網絡」的設置選項,然後使這將有助於獲得一個鎖更快,即使你沒有在你的代碼中使用NETWORK_PROVIDER選項。

這是因爲星曆和年曆數據告訴設備在當時(近似)位置應該查看哪些衛星應通過電話網絡傳輸。

1

我也有同樣的問題,並開始認爲GPS或程序出了問題。然後我在辦公室旁邊試了一下,它的工作很完美。嘗試在一個開放的空間或靠近窗口使用您的手機:)

歡呼聲。

0

獲取GPS定位可能需要相當長的一段時間,這取決於許多變量,如GPS衛星的位置以及您的GPS單元是否對衛星有清晰的視野。由於GPS信號非常弱,常常被建築物堵塞。因此,這也是您的用戶也會遇到的問題,因此,如果您的應用沒有得到修復或緩慢修復,請務必使您的應用也可用。

雖然開發者可能會提供設備虛假的位置,但您需要在設備的開發者選項中啓用「允許虛假地點」。這將加快發展。