任何人都使用Blackberry 5.0 API反向地理编码?

时间:2010-10-11 04:53:40

标签: blackberry blackberry-jde

因此黑莓文档向您展示了以下代码示例:

import net.rim.device.api.lbs.*;
import javax.microedition.location.*;

public class myReverseGeocode
{
    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)(45.423488 * 100000);
            int longitude = (int)(-80.32480 * 100000);

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

                if ( results != null && results.length > 0 )
                    addrInfo = results[0].getAddressInfo();
            }
            catch ( LocatorException lex )
            {
            }
        }
    };
}

如何使用上述代码在主应用程序中传递动态经度/纬度值?

1 个答案:

答案 0 :(得分:2)

这只是一个基本的java问题吗?你必须使用'final'关键字,以便可以将值传递给局部变量'thread'持有的匿名类

public myReverseGeocode(final double latArg, final double lonArg)
{
    Runnable thread = new Runnable()
    {
        public void run()
        {
            AddressInfo addrInfo = null;

            int latitude  = (int)(latArg * 100000);
            int longitude = (int)(lonArg * 100000);

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

                if ( results != null && results.length > 0 )
                    addrInfo = results[0].getAddressInfo();
            }
            catch ( LocatorException lex )
            {
            }
        }
    };
    reverseGeocode = new Thread(thread);
    reverseGeocode.setPriority(Thread.MIN_PRIORITY);
    reverseGeocode.start();

 }