保存网络位置为.txt文件(不使用GPS) [英] Save network location as a .txt file (Without using GPS)
本文介绍了保存网络位置为.txt文件(不使用GPS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是机器人编程初学者。我的研究生项目是跟踪一个移动设备,我需要在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
}
这篇关于保存网络位置为.txt文件(不使用GPS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文