在没有使用GPS和没有互联网的情况下获取当前位置

时间:2014-10-30 09:55:01

标签: android gps location

任何人都可以帮助我,如果有办法获得当前的纬度和经度而不使用GPS,因为它消耗电力而没有互联网,因为我需要在没有互联网服务的地方获得位置。

3 个答案:

答案 0 :(得分:1)

是......如果没有GPS和互联网连接,您可以通过NETWORK_PROVIDER获取当前位置

试试这段代码。

LocationManager lm = null;
boolean network_enabled = false;
    if(lm==null)
        lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    try{
    network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    }catch(Exception ex){}

   if(!network_enabled){
        AlertDialog.Builder dialog = new AlertDialog.Builder(context);
        dialog.setMessage(context.getResources().getString("Custom message"));
        dialog.setPositiveButton(context.getResources().getString(R.string.open_location_settings), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                // TODO Auto-generated method stub
                Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
                context.startActivity(myIntent);
                //get gps
            }
        });
        dialog.setNegativeButton(context.getString(R.string.Cancel), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                // TODO Auto-generated method stub

            }
        });
        dialog.show();

    }

答案 1 :(得分:0)

除非您缓存和离线地图并让用户选择他们在地图上的位置。

答案 2 :(得分:-1)

理论上如果你有一个gsm塔的列表及其位置,你可以得到手机连接的id并得到一个粗略的位置(如果我没有弄错的话,半径约为100公里)。

但是,由于实际上不可能,因此如果不使用这两种服务之一,则无法获取更新的位置数据。

但是,您可以使用此代码段获取缓存位置:

public Location getLastKnownLocation(Context context){

LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

return lastKnownLocation;
}