目標:確定GPS位置一次,然後將緯度/經度放入兩個單獨的EditText框中以向用戶顯示。Android GPS定位,不會傳遞位置
問題:我測試了我的方法,它在模擬器中正常工作,我發送它的GPS座標,它工作正常和丹迪。我在兩個獨立的設備(v2.1手機,v4.0 ICS平板電腦)上試用它,並且GPS圖標出現在通知中(都很好),但只是在那裏試圖確定位置。我已經測試了很多次,並且每次測試都給了大量時間。 編輯:當我走出去時,在手機上正常工作,所以我可以穿過這個。平板電腦仍然有問題。
我在布里斯班的中心,所以我懷疑它是一個位置問題 - 此外,谷歌地圖通過GPS定位我的工作得很好。
如果我關閉GPS,所以它默認回到網絡定位,它工作得很好,給我的位置。方法:
方法:
(我調用的方法);
public void locateCoordinates(EditText latitudeInput, EditText longitudeInput) {
// Find coordinates, place them in EditText boxes.
// Create the locating services if needed
if(locManager == null) {
locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
if(locListener != null) {
// Unregister listener from locManager (in case of double click of Locate button)
locManager.removeUpdates(locListener);
}
locListener = new LocListenerImpl(locManager, latitudeInput, longitudeInput);
if(locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, locListener);
} else if(locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, locListener);
Toast.makeText(this,
"GPS unavailable, trying network-based location instead.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,
"No locating methods enabled", Toast.LENGTH_SHORT).show();
}
}
(Listener Implementation Class);
public class LocListenerImpl implements LocationListener {
private LocationManager locManager = null;
private EditText latitudeInput = null;
private EditText longitudeInput = null;
public LocListenerImpl(LocationManager locManager, EditText latitudeInput, EditText longitudeInput) {
this.latitudeInput = latitudeInput;
this.longitudeInput = longitudeInput;
this.locManager = locManager;
}
public void onLocationChanged(Location location) {
if(location != null) {
latitudeInput.setText(String.valueOf(location.getLatitude()));
longitudeInput.setText(String.valueOf(location.getLongitude()));
locManager.removeUpdates(this); // Location found, unregister listener
}
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
我很努力地看到我做錯了什麼或者是什麼原因造成了這種情況。任何幫助感謝!
你是否在一個結構或以某種方式沒有一個清晰的天空視圖? – npinti 2012-07-26 05:16:38
我剛從外面走進了晴朗的藍天,試了一下,在我的手機上工作,但不是我的平板電腦。 我的平板電腦是華碩Eee Pad變壓器,所以它不是cheapie – TechnIx 2012-07-26 05:38:37
看看你是否可以在另一臺平板電腦上,或者嘗試在平板電腦上下載一些取決於應用程序的GPS並查看它是否有效。您的產品可能有缺陷。 – npinti 2012-07-26 05:47:18