Android 位置管理器问题

编程入门 行业动态 更新时间:2024-10-27 04:35:10
本文介绍了Android 位置管理器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

Android 位置管理器问题

本文发布于:2023-11-27 04:41:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636637.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   位置   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!