本地化是返回null。什么是错的code? [英] Localization is returning null. What is wrong with the code?

查看:148
本文介绍了本地化是返回null。什么是错的code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double longitude = 0;
double latitude = 0;


try {
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    longitude = location.getLongitude();
    latitude = location.getLatitude();

} catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

在此code,纬度和经度返回null.I不想使用互联网来获取位置。

In this code, the latitude and longitude is returning null.I want to get location without using internet.

推荐答案

有什么不对您的code,您正在使用GPS_PROVIDER需要开放天空场获取GPS信息。我建议你​​,如果你想获取侧GPS细节室以及使用NETWORK_PROVIDER。

There nothing wrong with your code, You are using GPS_PROVIDER which requires open sky field to fetch GPS Information. I suggest you to use NETWORK_PROVIDER if you want to fetch GPS details in side the room as well.

try 
{
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    longitude = location.getLongitude();
    latitude = location.getLatitude();

} catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

这篇关于本地化是返回null。什么是错的code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆