java - 从网络读取经纬度

标签 java android latitude-longitude

我正在使用以下代码获取纬度和经度。始终依赖网络提供商可以吗?

public static String getLatitudeLongitudeString() {
    LocationManager lm = (LocationManager) GlobalApplication
            .getAppContext().getSystemService(Context.LOCATION_SERVICE);

    Location location = lm
            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    if (location == null) {
        return "";
    } else {
        Geocoder geocoder = new Geocoder(GlobalApplication.getAppContext());
        try {
            List<Address> user = geocoder.getFromLocation(
                    location.getLatitude(), location.getLongitude(), 1);
            double lat = (double) user.get(0).getLatitude();
            double lng = (double) user.get(0).getLongitude();
            return lat + "," + lng;
        } catch (Exception e) {
            Trace.e("Failed to get latitude and longitude", e);
            return "";
        }
    }
}

最佳答案

老实说,它“取决于”。但我会说评论this article并找出选项的最佳组合是什么。您可能希望被动提供程序 (Froyo+) 从其他应用程序捕获一些 GPS 更新……也取决于您使用它的目的。如果它是一个 map 应用程序,那么您需要 GPS,但如果它只是用于“您在旧金山”类型的文本,那么不太准确就可以了...

关于java - 从网络读取经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11552008/

相关文章:

java - Swagger @ApiModelProperty 必填字段似乎被忽略(版本 1.3.6)

Java 运行时 -ERR 'fsctl 命令未找到

java - Hudson 为每个项目添加新的电子邮件地址

android - 如何自定义一个最小值在右边,最大值在左边的SeekBar

android - 去掉6位后的经纬度小数部分

java - 如何从图片中获取经纬度信息

java - 通过计算总和、频率和百分比来模拟掷骰子

android - 应用中心构建,错误 :/usr/bin/jarsigner failed with return code: 1

android - TGLAugmentedRealityView 类似 ANDROID 的库? (相机预览中的位置)

javascript - 查明 LngLat 点是否位于其他两个点之间