Android 位置管理器问题

Android Location Manager Issue(Android 位置管理器问题)

本文介绍了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 位置管理器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android 位置管理器问题

基础教程推荐