2014-10-30 98 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