Android系统。如何知道,如果检测到的位置是从GPS或网络服务提供商 [英] Android. How to know if location detected is from GPS or Network provider

查看:192
本文介绍了Android系统。如何知道,如果检测到的位置是从GPS或网络服务提供商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现从GPS和网络供应商检测位置并显示在谷歌地图的应用程序。我成功地做到了这一点,但我有一个问题:
我得到的提供商在我的活动的OnCreate()(它扩展了LocationListener的)

I'm trying to implement an application which senses position from both GPS and the network provider and shows it on a Google Map. I succeeded in doing this, but I have a question: I get the provider in the onCreate() of my Activity (it extends LocationListener)

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
location = locationManager.getLastKnownLocation(provider);

它工作得很好,我的问题是,当onLocationChange()被调用时,我应该采取不同的,如果调用它的提供者是GPS或网络。有没有办法知道哪些?
为了更清楚:

It works fine, my problem is that when onLocationChange() is called, I should act differently if the provider which called it is GPS or NETWORK. Is there a way to know which? To be more clear:

onLocationChanged(地点)之称,是有机会知道哪个供应商发出的呼吁?我已经尝试使用了如果对供应商字符串,但现在看来,这是行不通的。

When onLocationChanged(Location location) is called, is there a chance to know which provider made the call? I have tried using an if on the provider string but it seems it doesn't work.

推荐答案

检查精度为< =30米:

check that accuracy is <= 30m:

boolean isGPS = (location.getAccuracy() <= 30);

这篇关于Android系统。如何知道,如果检测到的位置是从GPS或网络服务提供商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆