Save network location as a .txt file (Without using GPS)(将网络位置保存为 .txt 文件(不使用 GPS))
问题描述
我是安卓编程的初学者.我的研究生项目是关于跟踪移动设备的,我需要将位置(不使用 GPS)保存为文本文件的代码.有人建议我这样做的代码.这对我有很大的帮助.
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.
推荐答案
试试这个.
locationManagerNetwork = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location2 = locationManagerNetwork
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location2 != null) {
String message = String
.format("Yout location :
Longitude: %1$s
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 卡
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 file in java code
}
这篇关于将网络位置保存为 .txt 文件(不使用 GPS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将网络位置保存为 .txt 文件(不使用 GPS)
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01