2010-02-10 65 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已激活位置。