Android 位置管理器问题
从下面的代码中,我获取了当前位置。
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 地图上绘制位置叠加层,并从位置提供商处决定位置叠加层的颜色。以下代码根据位置提供程序决定颜色。
Serviceprovider = GlobalLocation.getProvider();
if(Serviceprovider.equals("network"))
{
positionOverlay.iColor = 2;
}//End if
else if(Serviceprovider.equals("gps"))
{
positionOverlay.iColor = 1;
}//End else if
室外一切工作正常,但问题是,如果我在 GPS 不稳定的室内使用我的应用程序。提供商不使用网络
。网络提供商仅在 GPS 关闭时执行。请您指导一下,如果 GPS 不稳定,我该如何决定网络跳转。
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);
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题之前已经回答过。您需要添加两个不同位置的侦听器。一种用于 GPS,一种使用网络位置。基于蜂窝网络的位置侦听器。
GPS 只能在室外工作,但蜂窝网络可以在有信号的任何地方工作,但它不如 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 will work only outdoors but the cellular network would work anywhere there are signals however it isn't as accurate as the GPS is.
当您获得修复后,请使用
Location.getProvider()
了解使用了哪个提供程序。使用这篇详细文章来决定哪个 LocationProvider 是最好的。
When you get a fix, use the
Location.getProvider()
to know which provider was used.Use this elaborate article to decide which LocationProvider is the best.