Retrieve geospatial coordindates for an address by using geocoding
You can retrieve geospatial coordinates by invoking Locator.geocode(). When you invoke Locator.geocode(), you must specify a street address by using an AddressInfo object or a String object of address information. Your application must request geocoding information outside of the event dispatch thread. A successful request for geocoding information will return an array of Landmark objects.
Code sample: Retrieving geospatial coordinates for an address by using geocoding
import net.rim.device.api.lbs.*;
import javax.microedition.location.*;
public class myGeocode
{
private Thread geocoder;
public myGeocode()
{
geocoder = new Thread(thread);
geocoder.setPriority(Thread.MIN_PRIORITY);
geocoder.start();
}
Runnable thread = new Runnable()
{
public void run()
{
AddressInfo addrInfo = new AddressInfo();
addrInfo.setField(AddressInfo.STREET, "455 Phillip Street");
addrInfo.setField(AddressInfo.CITY, "Waterloo");
addrInfo.setField(AddressInfo.STATE, "Ontario");
addrInfo.setField(AddressInfo.POSTAL_CODE, "N2L 3X2");
addrInfo.setField(AddressInfo.COUNTRY, "Canada");
Coordinates coord = new Coordinates(43.28, -80.31, Float.NaN);
try
{
Landmark[] results = Locator.geocode(addrInfo, coord);
}
catch ( LocatorException lex )
{
}
}
};
}
Parent topic: Geocoding and reverse geocoding