2011-09-26 166 views
1

如何從黑莓應用程序中的GPS獲取當前位置。我試圖從模擬器Locationmanager method獲得位置,但是在我的設備中(Storm 2使用wifi),我無法獲得當前經緯度。在黑莓應用程序中從GPS獲取當前位置

我的代碼

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(); 

      // 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(); 
     } 
    } 

    public void providerStateChanged(LocationProvider provider, int newState) { 
     // no-op 
    } 
} 
+0

沒有關於您的問題足夠的信息 - 在GPS開啓?你的代碼是否符合黑莓的方式?你有沒有要求的應用程序的權限? – KevinDTimm

+0

GPS已啓用。是的代碼是在黑莓的方式和它的工作在模擬器後發送經緯度從GPS系統。第三關於許可?我不知道你在說什麼嗎? – Hitarth

+0

如果您有任何想法,請幫我 – Hitarth

回答

1

我發現這個第一的位置我找了風暴的問題:If you run the above code on your BlackBerry device (for instance a Storm), you will get a "GPS not allowed" LocationProvider exception. You need to get your code signed if you want to use the BlackBerry Storm with GPS in your app. To do this, you need to buy a $20 certificate from RIM.

+0

我的代碼已經被燒錄了。孔應用在設備中正常工作。我的應用程序有一個名稱爲「使用當前位置」的按鈕,從該按鈕單擊事件中獲取當前位置,然後繼續執行應用程序,但是在設備中,每當我獲得0.0經度和長時間時,我都有風暴2沒有SIM卡,我正在使用鑽孔應用程序使用wifi。 – Hitarth

+0

我的洞天西去解決這個問題,但我不能得到解決方案..如果你有任何演示或suggetion關於相同請幫助我 – Hitarth

+0

你看看http://stackoverflow.com/questions/2235660/setlocationlistener-not-working -in-黑莓-GPS編程 – KevinDTimm