如何让 Android LocationManager 使用 Cell 网络而不是 Wifi 网络?
我有一个使用 LocationManager 获取手机网络位置而不是 Wifi 位置的 Android 应用程序?如果我关闭了 Wifi 天线并执行以下操作:
LocationManager lm = (LocationManager) paramContext.getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
我总是返回 Wifi 位置,而不是蜂窝网络位置。我希望它返回手机位置,因为我已经离开 Wifi 位置。我尝试使用 LocationListener 但这似乎没有帮助。
这是在运行 Froyo 的 HTC Evo 上运行的。
谢谢!
I have an android application using LocationManager get the cell network location and not the Wifi location? If I have turned off the Wifi antenna and do the following:
LocationManager lm = (LocationManager) paramContext.getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
I am always returned the Wifi location and not the cell network location. I want it to return the cell location since I have moved fromthe Wifi location. I tried using a LocationListener but that doesn't seem to help.
This is running on an HTC Evo running Froyo.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不相信你可以。
网络位置提供商会查看 wifi 状态和小区状态,如果太旧则丢弃其中一个,或者通过 MASF 服务器将它们发送到 Google 位置服务器 (GLS)。那里所做的事情很神奇。但是您可以查看 NetworkProvider 的实现并了解如何调整您的代码。代码在这里: 网络位置提供商。
如果您只需要手机 ID,请查看电话管理器。在那里添加一个 PhoneStateListener 。
I don't believe you can.
Network location provider look at the wifi state and cell state, discard one if too old, or send them both over to the Google Location Server (GLS) via MASF server. What's done there is magic. But you can look at the implementation of NetworkProvider and see how to tweak your code. Codes are here: NetworkLocationProvider.
If you just want the cell ID, check out Telephony Manager. Add a PhoneStateListener there.
查看 Android 开发指南中的此部分:请求位置更新。基本上,您需要注册一个侦听器来获取位置更新,然后告诉 Android 您希望通过网络位置提供商获取这些更新。
然后,您应该能够使用 getLastKnownLocation() 获取最后一个已知位置和/或使用 LocationListener 中的 onLocationChanged() 。
Check out this section in the Android Dev Guide: Requesting Location Updates. Basically, you need to register a listener to get location updates, and then you tell Android that you want to get those updates with the network location provider.
You should then be able to get the last known location with getLastKnownLocation() and/or use the onLocationChanged() in the LocationListener.
我不知道你现在是否有答案,但是你是否尝试在网络信息上编写一些逻辑并获取你所在的网络类型?并拨打定位服务电话。
I don't if you have an answer by now, but did you try to write some logic on network info and get type of network you are in ?? and do a location service call.