Save network location as a .txt file (Without using GPS)

て烟熏妆下的殇ゞ 提交于 2019-12-01 04:08:34

问题


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.


回答1:


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



回答2:


only way to do that is to play with telephony manager and see what kind of information you can get about cell tower or network. Every network tower have unique id to it and from that you might be able to get an approx estimation depending upon signal strength and stuff of person's location.

I bet it'll be fun and tricky business.



来源:https://stackoverflow.com/questions/9733933/save-network-location-as-a-txt-file-without-using-gps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!