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 位置管理器问题
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01