安卓:不停位置计算 [英] Android: non-stop location calculation

查看:228
本文介绍了安卓:不停位置计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在做机器人的一个项目,我决定我的机器人感谢开车到Android手机(三星Galaxy S)。我的问题是我找不到来计算GPS位置每次的方式,我的意思是,驱动需要一个非常小的刷新时间,我无法得到它。起初,我以为我只是把这样的事情:

I'm currently doing a project of robotics and I decided to drive my robots thanks to an Android Phone (Samsung Galaxy S). My problem is that I can't find the way to calculate the GPS location "everytime", I mean, the driving requires a very tiny refresh-time, and I can't get it. At first, I thought I just had to put something like this:

mLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, this.refreshTime, 0, this);

通过refreshTime是一个可变的即时哪些值是500例如,但它不工作,因为我注意到了这个值只是一个暗示,不是一个真正的参数。所以我失去了^^

With refreshTime being a variable instant which values is 500 e.g., but it doesn't work, as I noticed this value is just a hint, not really a parameter. So i'm lost ^^

有没有办法做到这一点?

Is there any way to do that ?

本主题我的利润问你一个问题......你知道你们为什么当我设置GPS_PROVIDER没有被计算我的位置?我的卫星开启,但没有得到恢复,所以我想我做错了...

I profit in this topic to ask you a question... Do you know guys why my location is not being calculated when I set GPS_PROVIDER ? My satellites are turned on but nothing got returned so I guess I'm doing wrong...

下面是我的完整code:

Here's my complete code:

package com.pIndus.gps;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class Loc extends Activity {
    /** Called when the activity is first created. */

private long refreshTime = 1000;
private LocationManager mLocManager;
private LocationListener mLocListener;

@Override
public void onCreate(Bundle savedInstanceState)
{

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    /* Use the LocationManager class to obtain GPS locations */

    mLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    mLocListener = new MyLocationListener();

    mLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, this.refreshTime, 0, mLocListener);

}

/* Class My Location Listener */

public class MyLocationListener implements LocationListener

{



    @Override
    public void onProviderDisabled(String provider)
    {

        Toast.makeText( getApplicationContext(), "Gps désactivé", Toast.LENGTH_SHORT ).show();
        Log.i("GPS", "GPS Desactivé");

    }

    @Override
    public void onProviderEnabled(String provider)
    {

        Toast.makeText( getApplicationContext(),"Gps activé", Toast.LENGTH_SHORT).show();
        Log.i("GPS", "GPS Activé");

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)
    {
        Toast.makeText( getApplicationContext(),"Statut changé", Toast.LENGTH_SHORT).show();
        Log.i("GPS", "Statut changé");
    }

    @Override
    public void onLocationChanged(Location loc)

    {

        loc.getLatitude();

        loc.getLongitude();

        String Text = "Localisation courante:\n " + "Latitude : " + loc.getLatitude() + "\n" + "Longitude : " + loc.getLongitude();

        Log.i("GPS", "Localisation calculée");

        Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();

    }





}



public void onPause()
{
    mLocManager.removeUpdates(mLocListener);
    super.onPause();
}

public void onStop()
{
    mLocManager.removeUpdates(mLocListener);
    super.onStop();
}

}

希望你们理解我,我知道我的英语很糟糕。

Hope you guys understood me, I know my english is very bad.

非常感谢你的帮助。

推荐答案

我不认为你可以得到更大的频率1Hz的比... GPS接收芯片通常定期串行线发送测量值(逻辑) ,所以没有告诉它:我希望有一个位置,现在方式。这种有规律的时间间隔是可调的,太,但似乎不太可能的操作系统愿意将其调整到比1Hz的一个更小的值,只是因为一些应用要求。

I don't think you can get much greater frequency than 1Hz... GPS receiver chips usually send the measurements (logically) on a serial line at regular intervals, so there is no way of telling it "I want a location, NOW". This regular interval is adjustable, too, but it seems unlikely that the OS is willing to adjust it to a much smaller value than 1Hz, just because some app requested.

然而,由于GPS定位不准确,无论如何,这似乎并没有那么大的一个问题。 (除非你正在构建一个喷气动力的机器人飞机在飞行半每秒200米,当然:))

However, since GPS fixes aren't that accurate anyway, this doesn't seem to be a problem that big. (Unless you're building a jet-powered robot aircraft that flies 200 meters in half a second, of course :))

我建议使用卡尔曼滤波器或类似的方法来推断基于所述previous修复和速度的位置。 (如果您添加来自其他传感器,电机控制等一些更多的信息,这种估计可能是一个比你可以通过测量GPS位置的10次得到更好的。)

I would suggest using a Kalman filter or a similar method to extrapolate the position based on the previous fixes and speed. (If you add some more info from other sensors, motor control etc, this estimate may be much better than the one you could get by measuring GPS position 10 times a second.)

这篇关于安卓:不停位置计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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