2011-09-26 109 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