2014-10-30 99 views
-2

任何人能帮助我,如果有一种方式来获得当前的经纬度,而无需使用GPS,因为它消耗的功率和不上网,因为我需要得到地方的位置而不互联网服务。获取当前位置,而不使用GPS和没有上网的Android

+0

该类所做的工作对我来说。 https://stackoverflow.com/questions/14333736/locating-current-position-in-android-without-gps/14335343#14335343 – Ahsanwarsi 2015-07-27 07:37:23

回答

0

除非你缓存和离线地图,让用户挑选他们在地图上的位置。

-1

理论上,如果你有一个gsm塔的列表和他们的位置,你可以得到手机连接到的id,并得到一个粗略的位置(如果我没有弄错,大约有100km的半径)。

然而,因为这是不是真的有可能,你不能让不使用这两种服务的一个更新的位置数据。

你可以,但是,使用此片段获得缓存的位置:

public Location getLastKnownLocation(Context context){ 

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

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

return lastKnownLocation; 
} 
+0

这显示错误对话框的消息“不幸的app_name已停止”“ – 2015-04-05 12:39:00

+0

因为lastknownlication是空的。如果没有缓存的上次已知的定位 – jvrodrigues 2015-04-05 13:16:06

+0

会发生那么它的解决方案是什么? – 2015-04-14 03:37:36

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

没有工作,这需要网络 – 2014-10-31 14:16:44

+0

你期待什么吗?它会要求网络 – silverFoxA 2015-06-07 02:56:09