【问题标题】:How to get the Current Latitude and Longitude without Internet connection in android?如何在没有互联网连接的情况下在android中获取当前纬度和经度?
【发布时间】:2015-02-25 17:03:26
【问题描述】:

我正在创建一个与位置相关的应用程序,所以我需要在没有互联网连接的情况下获取当前的纬度和经度。

请帮帮我。我是位置管理器的新手。 建议表示赞赏。 谢谢问候。

【问题讨论】:

  • 使用 gps 可以在没有互联网的情况下获取当前位置。 stackoverflow.com/questions/22741632/…
  • @officebrain 此代码适用于 Internet。我需要在没有 Internet 连接的情况下获取纬度和经度。
  • 您可以停止上网并前往户外区域并获取当前位置。

标签: android google-maps gps location latitude-longitude


【解决方案1】:

有两种获取位置的方法

1)网络提供商

2)GPS 提供者

通过 GPS 提供商获取位置(无 Internet)使用LocationManager.GPS_PROVIDER 如下代码中所述

locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(
                                    LocationManager.GPS_PROVIDER,
                                    MIN_TIME_BW_UPDATES,
                                    MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

if (locationManager != null) {

            location =locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                            if (location != null) {
                                latitude = location.getLatitude();
                                longitude = location.getLongitude();

                            }
                        }

并了解 GPS 状态,无论是否启用

boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

以及删除更新

if(locationManager != null){locationManager.removeUpdates(this);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多