LocationManager 动态更改提供商

发布于 2024-11-06 21:36:42 字数 277 浏览 0 评论 0原文

如果设备丢失 GPS 信号,LocationManager 是否有能力进行更改,例如从 GPS 更改为更多课程提供者?

据我所知不是,但我不是 100% 确定,所以我需要问

(我问的原因是我很想制作自己的 LocationManagerManager 来处理这类问题。我可能让它接受多个 Criteria 对象在传统的 LocationManager 不够灵活的各种情况下按某种顺序进行尝试,但我不想重新发明轮子,例如,如果 Google 在某些未知的方法/类中处理了这个问题。 我)。

谢谢

Does LocationManager have the ability to change, from example, from GPS to a more course provider, should the device lose its GPS signal?

As far as I know it's not, but I'm not 100% sure, so I need to ask

(The reason I ask, is I'm tempted to make my own LocationManagerManager that handles these sorts of problems. I might have it accept multiple Criteria objects which are tried in some sort of order under various circumstances that the traditional LocationManager isn't flexible enough for. But I don't want to be reinventing the wheel, e.g. if Google have handled this in some method/class unknown to me).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

桃酥萝莉 2024-11-13 21:36:42

据我所知,您的选择可能是最好的主意。注册所有可用的提供商,然后返回最佳的可用位置值。

Not that I'm aware of: your option is probably the best idea. Register for all the available providers and then return the best available Location value.

沧桑㈠ 2024-11-13 21:36:42

是的,它已经可用了。只要谷歌一下,你一定能得到它。检查一下这个功能:

`

public boolean testProviders() {  
    Log.e(LOG_TAG, "testProviders");  
    String location_context = Context.LOCATION_SERVICE;  
    locationmanager = (LocationManager) getSystemService(location_context);  
    List<String> providers = locationmanager.getProviders(true);  
    for (String provider : providers) {    
        Log.e(LOG_TAG, "registering provider " + provider);  
        listener = new LocationListener() {  
            public void onLocationChanged(Location location) {  
                // keep checking the location - until we have  
                // what we need   
                //if (!checkLoc(location)) { 
                Log.e(LOG_TAG, "onLocationChanged");  
                locationDetermined = checkLoc(location);   
                //}   
            }  
            public void onProviderDisabled(String provider) { 
            }
            public void onProviderEnabled(String provider) {
            }
            public void onStatusChanged(String provider, int status,  
                    Bundle extras) {  
            }  
        };
        locationmanager.requestLocationUpdates(provider, 0,  
                0, listener);  
    }
    Log.e(LOG_TAG, "getting updates");  
    return true;  
}  

`

Yeah, it's already available. Just google it, u must get it. Check this function out :

`

public boolean testProviders() {  
    Log.e(LOG_TAG, "testProviders");  
    String location_context = Context.LOCATION_SERVICE;  
    locationmanager = (LocationManager) getSystemService(location_context);  
    List<String> providers = locationmanager.getProviders(true);  
    for (String provider : providers) {    
        Log.e(LOG_TAG, "registering provider " + provider);  
        listener = new LocationListener() {  
            public void onLocationChanged(Location location) {  
                // keep checking the location - until we have  
                // what we need   
                //if (!checkLoc(location)) { 
                Log.e(LOG_TAG, "onLocationChanged");  
                locationDetermined = checkLoc(location);   
                //}   
            }  
            public void onProviderDisabled(String provider) { 
            }
            public void onProviderEnabled(String provider) {
            }
            public void onStatusChanged(String provider, int status,  
                    Bundle extras) {  
            }  
        };
        locationmanager.requestLocationUpdates(provider, 0,  
                0, listener);  
    }
    Log.e(LOG_TAG, "getting updates");  
    return true;  
}  

`

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