简体   繁体   English

在网络与gps提供商之间进行连接

[英]Connecting between the network to the gps provider

I created an application that generates every 10 minutes a location if I moved 200 meter from the last location. 我创建了一个应用程序,如果我从上一个位置移了200米,则会每10分钟生成一个位置。 It's based on the network and the gps provider. 它基于网络和gps提供程序。

My problem is if I'm on the same place for a lot of time something wrong happend. 我的问题是,如果我在同一地方呆了很多时间,出了点问题。 Let's assume that the gps provider generates a location with 600 accuracy and the network provider generates a location with 800 accuracy. 假设gps提供商生成的位置精度为600,而网络提供商生成的位置精度为800。 My app will choose the gps provider and the next time that the gps will generate a location would be when I pass the 200 radios but looks like that the network location keep generating locations and some of them might be more accurate and then my location is changed while I'm on the same place. 我的应用将选择gps提供商,下次gps生成位置的时间将是当我通过200台收音机时,但看起来网络位置会继续生成位置,其中某些位置可能会更准确,然后更改我的位置而我在同一个地方。

This is a problem since staying in the same place for hours generates for me tone of locations instead of 1(which is what I'm looking for). 这是一个问题,因为在同一地方待几个小时会为我产生位置的语调,而不是1(这是我要的)。

I didn't attached code because it's more theoretical question I guess. 我没有附加代码,因为我猜这是理论上的问题。

EDIT code attachment 编辑代码附件

The update request: 更新请求:

mLocationManager.requestLocationUpdates(provider, TEN_SECONDS*6*10, TEN_METERS*20, listener);

Choosing between the locations: 在位置之间进行选择:

    if(gpsLocation == null || gpsLocation.getAccuracy() > 1000)
    {
        if(!(networkLocation == null || networkLocation.getAccuracy() > 1000))
            location = networkLocation;
    }
    else
        if(networkLocation == null)
        {
            if(gpsLocation.getAccuracy() < 1000)
                location = gpsLocation;
        }
        else
            if(gpsLocation.getAccuracy() < networkLocation.getAccuracy() && gpsLocation.getAccuracy() < 500)
                location = gpsLocation;
            else
                if(networkLocation.getAccuracy() < 1000)
                    location = networkLocation;
    if(location!=null)
    {
        Message.obtain(mHandler,
                UPDATE_LATLNG,
                location.getLatitude() + ", " + location.getLongitude()).sendToTarget();
         if (mGeocoderAvailable) 
            doReverseGeocoding(location);
    }

Here is the handler: 这里是处理程序:

   mHandler = new Handler() 
    {
        public void handleMessage(Message msg) 
        {
            if(msg.what == UPDATE_ADDRESS)
            {
                LocationService.this.address = (String) msg.obj;
                new SendLocation(LocationService.this.id,(String)msg.obj); //sends location to the db
                LocationService.this.gpsLocation = null;
                LocationService.this.networkLocation = null;
            }
        }
    };

If you get the location by GPS provider, it would be more accurate, so if next time you get a location by Network provider and it differs by more than say 500 meters then store this as the value, if the location is less than this value is given by network provider skip it. 如果您通过GPS供应商获取位置,则该信息会更加准确,因此,如果下次您通过网络供应商获取位置,且相差超过500米,则将该位置存储为值(如果位置小于此值)是由网络提供商给出的,跳过它。 If the location is provided by the GPS store this as the current location. 如果该位置由GPS提供,则将其存储为当前位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM