2010-02-10 105 views
1

我正在開發基於GPS的應用程序。我使用LocationProvider,並通過它的代碼調用setlocationListener就像setLocationListener不工作在黑莓GPS編程


LocationProvider lp = LocationProvider.getInstance(null); 
     if (lp != null) { 
      lp.setLocationListener(new LocationListenerImpl(), 2, 1, 1); 
     } else { 
      Dialog.alert("GPS NOT SUPPORTED!"); 
      retval = false; 
     } 
    } catch (LocationException e) { 
     System.out.println("GPS Error: " + e.toString()); 
    } 

    return retval; 
} 

private class LocationListenerImpl implements LocationListener { 
    public void locationUpdated(LocationProvider provider, Location location) { 
     if (location.isValid()) { 
      heading = location.getCourse(); 
      longitude = location.getQualifiedCoordinates().getLongitude(); 
      latitude = location.getQualifiedCoordinates().getLatitude(); 
      altitude = location.getQualifiedCoordinates().getAltitude(); 
      speed = location.getSpeed(); 
      System.out.println("Current latitude:"+latitude); 
      System.out.println("Current longitude:"+longitude); 
      System.out.println("Current speed:"+speed); 

      // This is to get the Number of Satellites 
      String NMEA_MIME = "application/X-jsr179-location-nmea"; 
      satCountStr = location.getExtraInfo("satellites"); 
      if (satCountStr == null) { 
       satCountStr = location.getExtraInfo(NMEA_MIME); 
      } 

      // this is to get the accuracy of the GPS Cords 
      QualifiedCoordinates qc = location.getQualifiedCoordinates(); 
      accuracy = qc.getHorizontalAccuracy(); 
     } 
    } 

它不給出一個錯誤,但甚至不工作了所以用same.the控制不得到轉移到LocationListenerImpl幫助() ... 我在黑莓8800模擬器上使用BlackBerry_JDE_PluginFull_1.0.0.67與eclipse-java-galileo-SR1-win32 .. 任何協助感謝.... 感謝您提前。

+0

你接受了一個答案或仍然需要任何幫助! – Swati 2010-06-17 10:15:46

回答

1

嘗試:

lp.setLocationListener(new LocationListenerImpl(), 2, -1, -1); 

度Acc對我 ü設置2,1,1這意味着時間間隔是2秒之後,位置更新用將被自動調用 1秒錶示超時 1秒錶示最大年齡

烏爾GPS超時之前走在前面的GPS位置更新method.so與將它設置爲默認值嘗試= -1

0

您必須啓用SIM卡的GPS ulator,當你嘗試時是否啓用?

如果您收到NullPointerException,那麼您應該在OS選項中檢查GPS已激活位置。