0

我有一个使用 GPS 查找您的位置的应用程序,然后它将位置写入 txt 文件

try
        {
            OutputStreamWriter fout= new OutputStreamWriter(openFileOutput("datosgps.txt", Context.MODE_APPEND));
                fout.append( latitude+longitude+"\n");

            Intent intent = new Intent(getApplicationContext(), aviso.class);
            startActivity(intent);

                fout.close();
        }
        catch (Exception ex)
        {
            Log.e("Ficheros", "Error");
        }

在 txt 文件中,我有这个:

 Latitud: 49.650 Longitud: 2.931
 Latitud: 49.655 Longitud: 2.939
 Latitud: 49.656 Longitud: 2.939
 Latitud: 49.657 Longitud: 2.939
 Latitud: 49.657 Longitud: 2.939

一个低于另一个。

每 2 分钟,它会写入 NEW 位置,我该怎么做才能检查 NEW 行是否与 LAST 行相同?

例如,我希望它阅读

纬度:49.656 经度:2.939

然后写入新位置

纬度:49.657 经度:2.939

检查它们是否相同

如果没有,什么也不做

阅读最后

纬度:49.657 经度:2.939

和新的位置

纬度:49.657 经度:2.939

如果是平等的做某事

任何建议将不胜感激

已编辑

What do you mean.. something like this?

        String newdata = latitude+longitude;
    if((newdata.equals(lastdata){

    //DO SOMETHING
    }
          try
                {


                    OutputStreamWriter fout= new OutputStreamWriter(

openFileOutput("datosgps.txt", Context.MODE_APPEND));
                fout.append( latitude+longitude+"\n");

                fout.close();
    String lastdata = latitude+longitude;

            }
            catch (Exception ex)
            {
                Log.e("Ficheros", "Error");
            }

现在我在 String 中有最后一个数据,在 .txt 中有一行,例如:

纬度:43.4556 经度:34.333

在 6 秒内,它将写入新数据并进行比较

newdata 与 lastdata 但第一次运行时, lastadata 不存在,然后崩溃。

感谢您的时间!

4

1 回答 1

1

Why not just hold on to the last values you wrote (store them in last_latitude and last_longitude) and then simply check if you new values are the same as these before deciding to write?

于 2013-08-23T13:48:36.753 回答