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

5

我是一名Android编程的初学者。我的毕业项目是关于跟踪移动设备,我需要代码将位置(不使用GPS)保存为文本文件。有人向我建议了执行此操作的代码。这对我来说将是很大的帮助。


2
在提问之前,请先搜索一下,这些问题已经有答案了。https://dev59.com/EnI-5IYBdhLWcg3woJ9J http://stackoverflow.com/questions/5844579/how-to-write-to-an-external-text-file-in-android https://dev59.com/Km455IYBdhLWcg3wCPfh - Ruuhkis
@Ruuhkis 谢谢。但是我的项目需要保存一个包含网络位置细节的文本文件。请帮帮我。 - Midhun Sivaraj
您可以轻松地将网络详细信息保存在文本文件中,就像打印出来一样。请参见下面。 - Ruuhkis
2个回答

2

试一试。

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 
}

-1

唯一的方法是通过与电话管理器进行交互,查看您可以获取有关基站或网络的哪些信息。每个网络塔都有唯一的ID,从中您可能能够根据信号强度和人员位置的情况得出大致估计。

我敢打赌这将是有趣而棘手的业务。


有没有办法使用代码找到大致的网络位置。我尝试了许多代码,但都不起作用。 - Midhun Sivaraj
许多代码和方法都是由stackoverflow用户描述的。请帮我,兄弟。 - Midhun Sivaraj
你有具体的问题吗? - Mayank
我想获取服务提供商网络位置并将其保存到SD卡上作为.txt文件。 - Midhun Sivaraj
你能发布一些从电话管理器获取的示例数据吗?从那里,我们可能能够找出一些东西。 - Mayank
请查看此帖子,https://groups.google.com/forum/?fromgroups#!topic/android-developers/ASVpv7RbLL8 - Mayank

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接