Android Location Manager Issue(Android 位置管理器问题)
问题描述
从下面的代码中,我得到了当前位置.
From the following code, I get the current location.
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
GlobalLocation = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);
获得位置后,我在 Google 地图上绘制位置叠加层,并从位置提供者那里决定位置叠加层的颜色.下面是根据 Location Provider 决定颜色的代码.
After getting the location I draw the location overlays on Google map and from location provider I decide the color of location overlays. Here is the following code which decide the color on the base of Location Provider.
Serviceprovider = GlobalLocation.getProvider();
if(Serviceprovider.equals("network"))
{
positionOverlay.iColor = 2;
}//End if
else if(Serviceprovider.equals("gps"))
{
positionOverlay.iColor = 1;
}//End else if
在室外一切正常,但问题是,如果我在 GPS 不稳定的室内使用我的应用程序.提供商不使用 network
.网络提供商仅在 GPS 关闭时执行.如果 GPS 不稳定,您能否指导我如何决定在网络上跳转.
Everything is working fine outdoor, but the problem is, if I use my application indoor where the GPS is not stable. Provider doesn't use network
. network provider execute only if the GPS is off. Can you kindly guide me that how can I decide the jump on network if GPS is not stable.
推荐答案
这个已经回答过了.您需要添加两个不同的位置侦听器.一种用于 GPS,一种用于网络位置.基于蜂窝网络的位置监听器.
This has been answered before. You need to add two different location listeners. One for the GPS and one using the network position. Cellular network based location listener.
GPS 只能在室外工作,但蜂窝网络可以在有信号的任何地方工作,但它不如 GPS 准确.
GPS will work only outdoors but the cellular network would work anywhere there are signals however it isn't as accurate as the GPS is.
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
locationListener2 = new MyLocationListener();
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, locationListener2);
这篇关于Android 位置管理器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android 位置管理器问题


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01