谷歌地图 - 位置使我真正的位置和0.6英里之间跳跃,(随机地点) [英] Google Maps - Location keeps jumping between my real location and 0.6 miles away (Random place)

查看:208
本文介绍了谷歌地图 - 位置使我真正的位置和0.6英里之间跳跃,(随机地点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了谷歌地图上v2中我的应用程序运行时,使用服务来获取用户的位置。问题是位置不断变化。它显示我的一点真正的位置,然后跳转到一个随机位置,我从来没有去过的。

I've got Google Maps v2 running on my app, using a service to get the users location. Problem is the location keeps changing. It shows my real location for a bit, then jumps to a random location that I've never been to before.

我是通过服务检查GPS /网络纬度/经度,并呼吁他们在我的地图类,在这里我再动画摄像机移动到我的位置。我真的不知道什么是错的,或者从哪里开始的这一个。

I'm check GPS/Network lat/lng via the service and calling them in my maps class, where I then animate the camera to move to my location. I don't really know what's wrong, or where to start with this one.

有谁知道这是什么样的问题呢?它莫名其妙给我。

Does anyone know what sort of problem this is? It's baffling to me.

我真的不知道是什么code发布。通过网络位置的精度1121米作为的地方通过GPS的定位精度约为31我使用的是 LocationListener的,并在 onLocationChanged 是说,它用我的网络位置,顿时精度提高到29米,然后又突然变成恢复到1121米。这种情况大约每分钟左右。很奇怪的行为。启用GPS,它就不能成为pferred选择反正$ P $?有没有一种方法,一旦它得到修复将其设置为我的preferred选择?

I don't really know what code to post. The accuracy of the location via network is 1121m where as the accuracy of the location via GPS is around 31. I'm using a LocationListener and in the onLocationChanged is says it's using my network location, suddenly the accuracy improves, to 29m, then it suddenly goes back up to 1121m. This happens about every minute or so. Very odd behaviour. With GPS enabled, shouldn't that be the preferred choice anyway? Is there a way to set it to my preferred choice once it gets a fix?

我的服务得到是这样的信息:

My service gets it's information like this:

public Location getLocation() {
    Log.i("getLocation", "Get location called");
    try {
        locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

        //Getting GPS status
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        //Getting network status
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            // no network provider is enabled and GPS is off.
            Log.d("NOT ENABLED", "PASSIVE PROVIDER");
            locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
            loc = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
            if (loc != null) {
                latitude = loc.getLatitude();
                longitude = loc.getLongitude();
                Log.i("PASSIVE_LOCATION", "Location: "+loc.toString());
            }
        }
        else {
            this.canGetLocation = true;
            if (isNetworkEnabled) {
                Log.d("Network", "Network");
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); 
                loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                if (loc != null) {
                    latitude = loc.getLatitude();
                    longitude = loc.getLongitude();
                    Log.i("NETWORK_LOCATION", "Location: "+loc.toString());
                }
            }
            if (isGPSEnabled) {
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                Log.d("GPS Enabled", "GPS Enabled");
                loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                if (loc != null) {
                    latitude = loc.getLatitude();
                    longitude = loc.getLongitude();
                    Log.i("GPS_LOCATION", "Location: "+loc.toString());
                }
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    //check provider & accuracy
    Log.d("PROVIDER", loc.getProvider());
    Log.d("ACCURACY", Float.toString(loc.getAccuracy()));
    return loc;

如果有人可以帮助我真的AP preciate它。谢谢你在前进。

If anyone could help I would really appreciate it. Thank you in advance.

推荐答案

我觉得这本身解决。它仅仅是因为准确的地点之间跳跃。一旦GPS精度比网络更好,它开始通过GPS更新。

I think this solved itself. It was jumping between locations simply because of accuracy. Once GPS accuracy was better than network, it started updating via GPS.

我也停止位置更新,一旦精度小于30 onLocationChanged 让我有更多的控制,不浪费用户的电池。

I'm also stopping location updates once the accuracy is less than 30 in onLocationChanged so I have a bit more control and don't waste the users battery.

这篇关于谷歌地图 - 位置使我真正的位置和0.6英里之间跳跃,(随机地点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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