Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Q3test
Posts: 77
Registered: ‎06-13-2013
My Device: 9900
My Carrier: blackberry cure

how to get address using longitute and latitude

I am using Geocoding .I want to get address or location using longitude and latitute .But when I used bedford .It is showing Atlantic ocean every time.

How to solve that problem .

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

 

 
Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to get address using longitute and latitude

These lines most likely cause the issue:
int latitude = (int)(52.135973);
int longitude = (int)(-0.466655);

by casting to int you remove all digits after the dot.
Take a look in the API:
latitude - The latitude of the address, specified as decimal degrees to five decimal places, multiplied by 100000
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.