我有简单的流程:当我点击按钮时,我应该只在当时获得当前的纬度/经度, 我正在使用LocationListner,但问题是onLocationChange()方法只在我改变位置时调用,否则给出0.00/0.00元。我做什么,请帮助我。如何一次获得当前的GPS位置?
1
A
回答
0
你真的不能要求Android立即为你提供当前的GPS位置,你最好的选择是等到它获得一个位置更改更新或使用最后已知的值!
您可以使用上次已知的位置。
看一看这里:
What is the simplest and most robust way to get the user's current location on Android?
希望这有助于
1
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
mlocListener);
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
loc.getLatitude();
loc.getLongitude();
Geocoder gcd = new Geocoder(getApplicationContext(),
Locale.getDefault());
try {
mAddresses = gcd.getFromLocation(loc.getLatitude(),
loc.getLongitude(), 1);
} catch (IOException e) {
}
String cityName = (mAddresses != null) ? mAddresses.get(0)
.getLocality() : TimeZone.getDefault().getID();
String countryName = (mAddresses != null) ? mAddresses.get(0)
.getCountryName() : Locale.getDefault().getDisplayCountry()
.toString();
mCurrentSpeed.setText("Longitude"+loc.getLongitude()+" Latitude"+loc.getLatitude());
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "Gps Disabled",
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) {
}
}
0
您可以实现您的位置侦听器,记住传递的位置,可能以某种方式对它们进行平均。
相关问题
- 1. 获得GPS当前位置
- 2. 如何获取当前的GPS位置?
- 3. 如何获得当前GPS位置的准确经纬度?
- 4. GPS当前位置
- 5. GPS纬度,一次又一次改变当前位置
- 6. 如何获得GPS位置一次,而没有自动更新?
- 7. 如何在Monodroid中获得一次性GPS位置
- 8. android gps如何显示当前位置
- 9. 使用GPS获取当前位置
- 10. blackberry gps获取当前位置地址?
- 11. 从GPS获取当前位置
- 12. 在GPS中获取当前位置?
- 13. 获取当前位置(GPS/WIFI)
- 14. 获取当前GPS位置android studio
- 15. 如何获得Android的GPS位置
- 16. 如何获得持续的GPS位置
- 17. 如何获得当前位置?
- 18. 如何获得当前位置
- 19. android gps当前位置
- 20. Gps当前位置问题
- 21. 获得用户的当前位置一次有权限
- 22. 如何获取Android中的当前GPS位置?
- 23. 如何获取Core Location的当前位置或GPS坐标?
- 24. 如何通过Android中的GPS获取当前位置
- 25. 获得当前位置定位的Android
- 26. 如何获得当前位置在iphone上的地图位置
- 27. 如何从当前位置获得10个最近的位置
- 28. 无法获得GPS位置
- 29. 如何获得当前位置(经度,纬度),而gps关闭使用FusedLocationApi android
- 30. 如何使用Google App或GPS获取当前位置?
http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-位置编程功能于安卓 – marcinj