views:

33

answers:

1

So the blackberry documentation shows you the following code example:

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 )
            {
            }
        }
    };
}

How do I use the above mentioned code to pass in dynamic longitude/latitude values in my main application?

+2  A: 

Is this just a basic java question? You have to use the 'final' keyword, so that the values can be passed in to the anonymous class held by the local variable '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();

 }
Michael Donohue
Thank You Michael.
jini
The latArg and lonArg still cannot be resolved in run(). That is they are not passed/accessible in the run method of runnable.
jini
what error do you get?
Michael Donohue
When I highlight over latArg it says: "latArg cannot be resolved". It is also underlined in red. The IDE I am using is eclipse with blackberry JDE 5.0 plugin.
jini
Sorry, I misread the scope of the myReverseGeocode function. I just edited my answer to fix the problem.
Michael Donohue
Michael, thanks so much. I truly appreciate it and sorry if I lack clarity on certain questions.
jini