gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:29 26 4
gpt4 key购买 nike

我是 android 编程的初学者。我的研究生项目是关于跟踪移动设备的,我需要代码将位置(不使用 GPS)保存为文本文件。有人建议我这样做的代码。这对我有很大的帮助。

最佳答案

试试这个。

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 coordinates in a text file
}

用于写入sd卡

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 file in java code
}

关于java - 将网络位置保存为 .txt 文件(不使用 GPS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9733933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com