我如何在黑莓得到纬度和经度? [英] How i can get Latitude and Longitude in blackberry?

查看:102
本文介绍了我如何在黑莓得到纬度和经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发黑莓具有GPS功能的应用程序。所以首先我想获得当前的纬度和经度,但它会dipslay例如超时等待GPS loaction。下面我在code获取经纬度和长期的当前位置。

i am developing app in Blackberry which have GPS Functionality. so first i want to get Current latitude and longitude but it will dipslay like time out while waiting for GPS loaction. Below in my code for getting lat and long of current location.

public class LocationScreen extends MainScreen 
{
      public LocationScreen() 
      {
        super();
        final LabelField lfLocation = new LabelField();
        new Thread()
        {
          public void run() 
          {
            LocationHandler lh = new LocationHandler();
            final String msg = "Long: " + lh.getCurrentLongitude() + ", Lat: " + lh.getCurrentLatitude();

            Application.getApplication().invokeLater(new Runnable() 
            {
              public void run() 
              {
                lfLocation.setText(msg);
                add(new LabelField("Lat and Long=="+msg));
              }
            });
          }
        }.start();
        this.add(lfLocation);
      }
    }

**Second Class**

public class LocationHandler 
{
  private LocationProvider locationProvider;
  private Location currentLocation;
  public LocationHandler()  
  {
    try 
    {
      locationProvider = LocationProvider.getInstance(null);
      currentLocation = locationProvider.getLocation(60);
    }
    catch (final Exception e) 
    {
      Application.getApplication().invokeLater(new Runnable() 
      {
        public void run() 
        {
          Status.show(e.getMessage());
        }
      });
    }
  }
  public double getCurrentLongitude() 
  {
    if(currentLocation != null)
      return currentLocation.getQualifiedCoordinates().getLongitude();
    return -1;
  }
  public double getCurrentLatitude() 
  {
    if(currentLocation != null)
      return currentLocation.getQualifiedCoordinates().getLatitude();
    return -1;
  }

我在做什么错在我的code,请帮助我。
感谢名单提前。

what i am doing mistake in my code please help me. Thanx in advance.

推荐答案

请简单写下低于code run方法

private BlackBerryCriteria blackBerryCriteria = null;
private BlackBerryLocation blackBerryLocation = null;
private BlackBerryLocationProvider blackBerryLocationProvider = null;
double lat = 0.0;
double lng = 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();

            lat = qualifiedCoordinates.getLatitude();
            lng = qualifiedCoordinates.getLongitude();}catch(Exception e)
        {
            System.out.println("Error in location :"+e.toString());
            System.out.println("Error in location :"+e.getMessage());
        }

试试这个它使用 BIS 在我的设备工作正常。
我希望它会帮助你。

Try this it working fine in my device using BIS. i hope it will help you ..

这篇关于我如何在黑莓得到纬度和经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆