不能够通过GPS获得的位置:android [英] Not able to get Location by GPS : Android

查看:199
本文介绍了不能够通过GPS获得的位置:android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我试图用GPS让我的位置。
我已经包括的权限:

 <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.INTERNET对/>

每当我试图使用getLastKnownLocation我得到空的对象从的LocationManager得到我的位置。此外,全球定位系统被使能。这里是我的code:

 的LocationManager的LocationManager =(的LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
地点位置;
如果(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
    Log.d(ManualLog,GPS_DISABLED);
    意图settingsIntent =新意图(Settings.ACTION_LOCATION_SOURCE_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(settingsIntent);
}其他{
    Log.d(ManualLog,GPS_ENABLED);
    位置= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}


解决方案

您运行它在模拟器或设备?
如果模拟器,你可能需要通过模拟器控制手动发送GPS数据模拟器。在Eclipse中,你可以找到它窗口>打开透视图> DDMS。

如果您在设备上运行,是有可能您的设备从未获得过GPS信号?

I am new to android. I am trying to get my location using GPS. I have included the permissions:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

Whenever I am trying to get my Location from LocationManager using getLastKnownLocation I am getting null object. Also, GPS is enabled. Here is my code:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location location;
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
    Log.d("ManualLog", "GPS_DISABLED");
    Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(settingsIntent);
} else {
    Log.d("ManualLog", "GPS_ENABLED");
    location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}

解决方案

Are you running it on emulator or device? If on emulator, you may need to send GPS data manually to emulator via "emulator control". In eclipse, you can find it Window>Open Perspective>DDMS.

If you are running on device, is it possible your device never received a GPS signal before?

这篇关于不能够通过GPS获得的位置:android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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