保存网络位置为.txt文件(不使用GPS)位置、文件、网络、txt

2023-09-06 10:38:04 作者:我随我爸

我是机器人编程初学者。我的研究生项目是跟踪一个移动设备,我需要在code保存位置(不使用GPS)为文本文件。有人建议我C $ CS的$这样做的。这将是对我来说是很大的帮助。

解决方案

试试这个。

  locationManagerNetwork =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    地点地点2 = locationManagerNetwork
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

     如果(LOCATION2!= NULL){
                字符串消息=字符串
                        .format(YOUT位置:\ñ经度:%1 $ S \北纬:%2 $ S,
                                location2.getLongitude(),location2.getLatitude());
                Toast.makeText(getApplicationContext(),消息,Toast.LENGTH_LONG)
                        。显示();


    //这里使用的文件作家,如果你想要写在一个文本文件中的coordinastes
            }
 

写入SD卡

 文件SD卡= Environment.getExternalStorageDirectory();
        文件F =新的文件(SD卡,/ yourfile);

如果(!f.exsist()){
f.createNewFile();
//使用outwriter这里,OutputStream的搜索如何编写成的Java code进行TET文件
}
 

保存文件到桌面上,无法保存 ,系统提示找不到文件,保存到别的地方就可以

I am a beginner in android programming. My Graduate project is about tracking a mobile device and i need the code to save the location( Without using GPS) as a text file. Someone suggest me the codes for doing that. It will be a great help for me.

解决方案

Try this.

locationManagerNetwork = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location2 = locationManagerNetwork
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

     if (location2 != null) {       
                String message = String
                        .format("Yout location : \n Longitude: %1$s \n Latitude: %2$s",
                                location2.getLongitude(), location2.getLatitude());
                Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG)
                        .show();


    //use here file writer if you want to write the coordinastes in a text file
            }

for writing sd card

File sdcard = Environment.getExternalStorageDirectory();
        File f = new File(sdcard, "/yourfile");

if(!f.exsist()){
f.createNewFile();
//Use outwriter here, outputstream search how to write into a tet file in java code 
}