我使用 NETWORK_PROVIDER
获得纬度
和经度。
我心中已经已经检查设置中的位置与安全性,并启用使用无线网络。但isProviderEnabled(LocationManager.NETWORK_PROVIDER)
总是返回假
。
谁能帮助我?预先感谢您!
下面是我的code:
LocationManager locManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
布尔isEnableGPS = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
布尔isEnableNTW = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.d(TAG,isEnableGPS +,+ isEnableNTW);
在AndroidMainfest.xml许可
<使用-权限的Android:名称=android.permission.INTERNET对/>
<使用-权限的Android:名称=android.permission.ACCESS_FINE_LOCATION/>
<使用-权限的Android:名称=android.permission.ACCESS_COARSE_LOCATION/>
解决方案
确认,基于网络的位置在手机的设置中启用。您可以检测到这种情况并提示用户启用它,如果你真的需要它。
我相信这是code线,推出这一活动。
activity.startActivity(新意图(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
ACTION_LOCATION_SOURCE_SETTINGS
这篇文章解释了它的http://emobiledude.com/fix-waiting-for-location-in-google-maps-after-android-4-2-update/
I am using NETWORK_PROVIDER
to get latitude
and longitude
of the place.
I'v already check the setting in the "location & security" and enable "use wireless networks". But "isProviderEnabled(LocationManager.NETWORK_PROVIDER)"
always return false
.
Can anyone help me? Thank you in advance!
Here is my code :
LocationManager locManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean isEnableGPS=locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isEnableNTW=locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.d(TAG, isEnableGPS+", "+isEnableNTW);
permission in the AndroidMainfest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
解决方案
Make sure that network based location is enabled in the phone's settings. You can detect this situation and prompt the user to enable it if you really need it.
I believe this is the line of code to launch this activity.
activity.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
ACTION_LOCATION_SOURCE_SETTINGS
This article explains it http://emobiledude.com/fix-waiting-for-location-in-google-maps-after-android-4-2-update/
上一篇:差异的B / W bitmap.recycle()和位图= NULL位图、差异、recycle、bitmap
下一篇:安卓:崩溃:二进制XML文件行:错误充气类(使用SurfaceView)错误、文件、XML、SurfaceView