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

标签 java android geolocation

我是 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/

相关文章:

java - 如何使用 typedQuery 在 Criteria api 上添加分页?

java - SQL Azure 和连接池

android - 如何在后台线程启动GPS定位?

javascript - 错误 : Did not check() all arguments during publisher

geolocation - 按经纬度查找电话区号

java - 为什么IntelliJ的菜单和上下文菜单打开后立即关闭?

java - 将 Spring Boot 应用程序作为 Docker 镜像启动时无法解析配置类

适用于 Zebra RW420 打印机的 Android 打印应用程序

Android:这个 Paint 标志是做什么的:DEV_KERN_TEXT_FLAG?

android - Android 应用程序如何将 Easy Stars 添加到 Google map ?