如何使用经度和纬度获取地址

时间:2013-12-03 05:39:58

标签: java blackberry latitude-longitude

我正在使用地理编码。我想使用经度和纬度获取地址或位置。但是当我使用 bedford 时。它每次都显示大西洋

package mypackage;
import javax.microedition.location.AddressInfo;
import javax.microedition.location.Landmark;

import net.rim.device.api.lbs.Locator;
import net.rim.device.api.lbs.LocatorException;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class myReverseGeocode extends MainScreen
{
    private Thread reverseGeocode;

    public myReverseGeocode()
    {
        reverseGeocode = new Thread(thread);
        reverseGeocode.setPriority(Thread.MIN_PRIORITY);
        reverseGeocode.start();
    }

    Runnable thread = new Runnable()
    {
        public void run()
        {
            AddressInfo addrInfo = null;

            int latitude  = (int)(52.135973);
            int longitude = (int)(-0.466655);

            try
            {
                Landmark[] results = Locator.reverseGeocode
                 (latitude, longitude, Locator.ADDRESS );

                if ( results != null && results.length > 0 )
                    addrInfo = results[0].getAddressInfo();

                synchronized(Application.getEventLock())
                {
                       add(new LabelField("------------------------"+addrInfo));
              add(new LabelField("------------------------"+addrInfo.getField(addrInfo.BUILDING_FLOOR)));
              add(new LabelField("------------------------"+addrInfo.getField(addrInfo.CITY)));
              add(new LabelField("------------------------"+addrInfo.hashCode()));
              add(new LabelField("------------------------"+addrInfo.getField(addrInfo.BUILDING_NAME)));
              add(new LabelField("------------------------"+addrInfo.getField(addrInfo.COUNTRY)));
              add(new LabelField("------------------------"+addrInfo.getField(addrInfo.STREET)));


                }
          //      add(new LabelField("---"+addrInfo));
            }
            catch ( LocatorException lex )
            {

                  synchronized(Application.getEventLock())
                  {

                      System.out.print("EVENT THREAD\n");
                      Dialog.inform("Posted!"+lex);
                  }
            }
        }
    };
}

1 个答案:

答案 0 :(得分:2)

reverseGeocode方法需要两个整数作为参数,但根据文档,这些是“十进制度到五位小数,再乘以100000 ”。

只需创建一个新的Coordinates实例并使用该方法的第二个版本:

    Coordinates coords = new Coordinates(52.135973, -0.466655, 0);
    Landmark[] results = Locator.reverseGeocode(coords, Locator.ADDRESS );