【问题标题】:get current location without using GPS and without internet in android在不使用 GPS 且在 android 中没有互联网的情况下获取当前位置
【发布时间】:2014-10-30 09:55:00
【问题描述】:

如果有一种方法可以在不使用 GPS 的情况下获取当前纬度和经度,那么任何人都可以帮助我,因为它会消耗电力并且没有互联网,因为我需要在没有互联网服务的地方获取位置。

【问题讨论】:

标签: android gps location


【解决方案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();

    }

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-09-11
      • 2011-10-05
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多