2010-04-17 147 views

回答

8

在嘗試獲取位置信息時,有幾種不同的方法可以降低使用的功率。

  1. 使用last known location而不是嘗試確定當前位置。

    // Get a Location Manager 
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    
    // Try to get the last GPS based location 
    Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    
    // Fall back to cell tower based location if no prior GPS location 
    if (l == null) { 
        l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
    } 
    
  2. 使用較便宜的位置提供商。您可以直接選擇LocationManager.NETWORK_PROVIDER或指定您關心的criteria,然後讓Android告訴您要使用哪個位置提供程序。

    // Select the criteria you care about 
    Criteria c = new Criteria(); 
    c.setAccuracy(Criteria.ACCURACY_COARSE); 
    c.setPowerRequirement(Criteria.POWER_LOW); 
    
    // Let the system tell you what provider you should use for your criteria 
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    String p = lm.getBestProvider(c, true); 
    
    // Call other Location Manager functions using the above provider... 
    
+0

非常感謝我在50%實現 – Narasimha 2010-04-21 11:40:07

+0

在我的應用程序的電池使用電池使用率和內存使用情況及其適用的另一種方式 – Narasimha 2010-04-22 05:37:46

相關問題