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

2023-09-03 20:53:35 作者:薛:好好薛习、我要薛好

从以下code,我得到的当前位置。

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

获取位置后,我得出的位置叠加在谷歌地图和位置提供我决定位置重叠的颜色。这是下面的code这决定位置提供者的基础上的颜色。

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并不稳定。供应商不使用网​​络。网络提供商执行仅如果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 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);