Android 位置管理器问题管理器、位置、问题、Android

2023-09-07 04:50:51 作者:适合网红用的 个性好听的网红昵称

从下面的代码中,我得到了当前位置.

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