获得经度和纬度的Android总是返回0.0

获得经度和纬度的Android总是返回0.0,第1张

概述我正在尝试获取 android的经度和纬度,这是我的代码: LocationManager locationManager = (LocationManager) this_activity.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new MyL 我正在尝试获取 android的经度和纬度,这是我的代码:
LocationManager locationManager = (LocationManager)            this_activity.getSystemService(Context.LOCATION_SERVICE);    LocationListener locationListener = new MyLocationListener();    locationManager.requestLocationUpdates(            LocationManager.GPS_PROVIDER,5000,10,locationListener); public class MyLocationListener implements LocationListener {    @OverrIDe    public voID onLocationChanged(Location loc) {        longitude = Double.toString(loc.getLongitude());        latitude = Double.toString(loc.getLatitude());    }    @OverrIDe    public voID onProvIDerDisabled(String provIDer) {}    @OverrIDe    public voID onProvIDerEnabled(String provIDer) {}    @OverrIDe    public voID onStatusChanged(String provIDer,int status,Bundle extras) {}}

清单Permissions:

<uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" />

经度和纬度我总是得到0.0秒

解决方法 除了@AshishPedhadiya提到你只听GPS提供商的权限.
LocationListener locationListener = new MyLocationListener();locationManager.requestLocationUpdates(        LocationManager.GPS_PROVIDER,locationListener);

GPS无法在里面工作.因此,当您测试应用程序时,它几乎总是会返回(0,0)位置.您可能也想收听NETWORK_PROVIDER,如果没有GPS位置,它会估计来自手机信号塔和WiFi点的位置.

locationManager.requestLocationUpdates(        LocationManager.NETWORK_PROVIDER,locationListener);

此外,要获取快速地理位置,请查看Application.getLastKNownLocation()方法.

总结

以上是内存溢出为你收集整理的获得经度和纬度的Android总是返回0.0全部内容,希望文章能够帮你解决获得经度和纬度的Android总是返回0.0所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1136759.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存