【问题标题】:blackberry location-based services黑莓定位服务
【发布时间】:2011-08-02 01:36:11
【问题描述】:

谁能告诉我如何使用黑莓定位服务? 我正在开发一个黑莓手机应用程序的项目。我以前从未有过黑莓,也没有与任何供应商签订合同(只有一张来自 3 的 sim 卡和移动设备 9000 OS 4.6)。

在项目中,我目前正在尝试使用以下代码来检索当前位置(起点)和目标位置(终点)的坐标。它在模拟器上工作得很好,但在设备上什么也没有。我应该与供应商签订合同吗?这是否只需要 GPS 或互联网,或两者都可以工作?

代码:

String destination = "London";

final Landmark[] landmarks = Locator.geocode(destination.replace('\n', ' '), null);
Coordinates endPoint = landmarks[0].getQualifiedCoordinates();
// Get a location provider.
LocationProvider provider = LocationProvider.getInstance(null);
if (provider == null)
{
    throw new IllegalStateException("No LocationProvider Available!!");
}
// Try to fetch the current location and get the coordinates of the current location.
Coordinates startPoint = provider.getLocation(-1).getQualifiedCoordinates();

double destiinationlatitude = endPoint.getLatitude();
double currentlatitude = startPoint.getLatitude();

提前谢谢你

【问题讨论】:

    标签: blackberry


    【解决方案1】:

    要在 5.0 之前的任何版本上获取 GPS 位置,您必须实例化这些东西

    1. 标准
    2. 位置提供者
    3. 位置对象(由位置提供者完成)

    这是你实例化的东西:

    Criteria criteria = null;
    LocationProvider provider = null;
    javax.microedition.location.Location location = null;
    

    之后,您必须为 Criteria 赋值,使用条件获取 LocationProvider 的实例,并使用 LocationProvider 获取 Location。

    criteria = new Criteria();
    criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);
    criteria.setHorizontalAccuracy(50);
    criteria.setVerticalAccuracy(50);
    criteria.setCostAllowed(true);
    provider = LocationProvider.getInstance(criteria);
    location = provider.getLocation(5);
    

    请注意,标准将确定您是使用 GPS、Wifi 辅助定位还是 Cellsite 定位,有关标准设置的更多信息请参见此处:http://www.blackberry.com/developers/docs/4.5.0api/javax/microedition/location/Criteria.html

    之后,调用方法来获取坐标:location.getQualifiedCoordinates()

    就是这样......你应该从一个单独的线程中调用它。并且实际的位置管理代码应该在 try-catch 块上,但 IDE 会帮助您。

    【讨论】:

      【解决方案2】:

      在这段代码中,我们看到了哪些模式可用于获取坐标(即,如果手机没有 GPS,那么它应该使用卫星信息。)

      可用模式正在检索经纬度。

      创建了一个地图视图(MapView 是地图,您设置所需的规格,例如缩放、纬度、经度等)然后您调用地图,设置的缩放、纬度、经度等将应用于映射到屏幕上的地图。

      CustomMapField mMapField;
      Coordinates mCoordinates;
      BlackBerryCriteria blackBerryCriteria = null;
      BlackBerryLocation blackBerryLocation = null;
      BlackBerryLocationProvider blackBerryLocationProvider = null;
      double Doublelat = 0.0;
      double Doublelng = 0.0;
      blackBerryCriteria = new BlackBerryCriteria();
      if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)){
        blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSITE);
      }else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)){
        blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST);
      }else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)){
        blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS);
      }else{
         blackBerryCriteria.setCostAllowed(true);
         blackBerryCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
      } try {
         blackBerryLocationProvider = (BlackBerryLocationProvider)          BlackBerryLocationProvider.getInstance(blackBerryCriteria);
         blackBerryLocation = (BlackBerryLocation) blackBerryLocationProvider.getLocation(60);
         QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();
         Doublelat = qualifiedCoordinates.getLatitude();
         Doublelng = qualifiedCoordinates.getLongitude();
         mCoordinates = new  Coordinates(Doublelat, Doublelng, 0);
         MapView mapView = new MapView();
         mapView.setLatitude(finalintlat);
         mapView.setLongitude(finalintlng);
         mapView.setZoom(10);
         MapsArguments mapsArgs = new MapsArguments(mapView);
         Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs);
      }catch(Exception e){
         System.out.println("Error in location :"+e.toString());
         System.out.println("Error in location :"+e.getMessage());
      }
      

      【讨论】:

      • 这里有一些解释会有所帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多