Android 位置管理器问题

发布于 2024-11-02 11:27:15 字数 966 浏览 7 评论 0原文

从下面的代码中,我获取了当前位置。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你对谁都笑 2024-11-09 11:27:15

这个问题之前已经回答过。您需要添加两个不同位置的侦听器。一种用于 GPS,一种使用网络位置。基于蜂窝网络的位置侦听器。

GPS 只能在室外工作,但蜂窝网络可以在有信号的任何地方工作,但它不如 GPS 准确。

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);

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.

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);
凉城已无爱 2024-11-09 11:27:15

当您获得修复后,请使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文