Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设备在Android中脱机时的位置纬度和经度_Android - Fatal编程技术网

设备在Android中脱机时的位置纬度和经度

设备在Android中脱机时的位置纬度和经度,android,Android,如果android设备处于脱机状态,通过编程查找和获取位置纬度和经度坐标值的可能方法是什么?这可能吗?如果是,可能的方法是什么?我想知道在这种情况下,如果没有互联网,就意味着没有移动网络/WIFI???试试下面的代码,它会告诉你网络提供商提供的位置 LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLoc

如果android设备处于脱机状态,通过编程查找和获取位置纬度和经度坐标值的可能方法是什么?这可能吗?如果是,可能的方法是什么?我想知道在这种情况下,如果没有互联网,就意味着没有移动网络/WIFI???

试试下面的代码,它会告诉你网络提供商提供的位置

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if(location==null){
        location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
或者通过这个链接


如果没有Internet连接,您可以显示警告对话框,告知用户启用Internet/ 使用此代码可以帮助您启用internet

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("YOU ARE NOT CONNECTED WITH INTERNET")
                .setCancelable(false)
                .setPositiveButton("ENABLE INTERNET",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                Intent callInternetsettingIntent = new Intent(
                                        android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);

                                startActivity(callInternetsettingIntent);
                            }
                        });
        builder.setNegativeButton("CANCEL",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }

                });
        AlertDialog alert = builder.create();
        alert.show();

当你说离线时,你是说GPS被禁用,还是说它没有连接到GPS、Wifi或移动网络。是的,这是可能的,但你需要开始解释你想要的用例。这比我们解释你可以使用的许多选项要简单得多。如果你说没有互联网连接就意味着离线,那么你可以使用GPS提供商,这是获取lat langi想要知道的情况下的lat langi的最佳方法,如果没有互联网就意味着没有移动网络/WIFI???如果你说没有移动网络/WIFI,然后你必须只使用gps。你的代码首先从gps提供商那里获得位置,而不是网络提供商。如果没有互联网呢?首先,它将尝试从gps获取位置。如果gps关闭,它将返回为空。这就是为什么我把iLocation==null条件