Exemplo de código: Obter um endereço para coordenadas geográficas usando geocodificação reversa

O seguinte exemplo de código demonstra como obter um nome de endereço usando uma solicitação de geocodificação reversa assíncrona. A solicitação especifica que o servidor deve retornar um endereço preciso de rua, o qual é indicado pelo parâmetro ReverseGeocodeExchange.ADDRESS, que é passado em geocode(). Quando o aplicativo recebe os resultados da solicitação, ele exibe o endereço na tela.
import net.rim.device.api.lbs.maps.MapDimensions;
import net.rim.device.api.lbs.maps.model.*;
import net.rim.device.api.lbs.maps.server.*;
import net.rim.device.api.lbs.maps.server.exchange.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
import java.util.Vector;
public class ReverseGeocodingDemo extends UiApplication
{
    public static void main(String[] args)
    {
        ReverseGeocodingDemo app = new ReverseGeocodingDemo();
        app.enterEventDispatcher();
    }
    public ReverseGeocodingDemo()
    {
        pushScreen(new ReverseGeocodingDemoScreen());
    }
    public class ReverseGeocodingDemoScreen extends MainScreen
    {
        private LabelField _resultsField;
        public ReverseGeocodingDemoScreen()
        {
            setTitle("Reverse Geocoding Demo");
            _resultsField = new LabelField();
            add(_resultsField);  
            // Location for the request.
            MapPoint origin = new MapPoint(43.4815, -80.5407);
            // Create an instance of the class that implements 
            // ServerExchangeCallback.
            MyServerExchangeCallback callback = new MyServerExchangeCallback();
            try
            {
                // Initiate the reverse geocoding request.
                ReverseGeocoder.getInstance().reverseGeocode(callback, origin, 
                        ReverseGeocodeExchange.ADDRESS, 1, 0);
            } 
            catch (ReverseGeocodeException e)
            {
                // Do something with the exception.
            }   
        }
        public class MyServerExchangeCallback implements ServerExchangeCallback
        {
            public void requestSuccess(ServerExchange exchange)
            {
                // StringBuffer used to display the location information from 
                // the request.
                StringBuffer buffer = new StringBuffer();
                if(exchange instanceof ReverseGeocodeExchange)
                {
                    // Cast the Exchange object to a ReverseGeocodeExchange 
                    // object and retrieve the Vector of results.
                    ReverseGeocodeExchange reverseGeocodeExchange = 
                            (ReverseGeocodeExchange)exchange;
                    Vector results = reverseGeocodeExchange.getResults();
                    // Iterate through each MapLocation object in the Vector.
                    for(int i = 0; i < results.size(); i++)
                    {
                        // Retrieve info from the MapLocation object
                        // and append it to the StringBuffer.
                        MapLocation location = (MapLocation) results.elementAt(i);
                        buffer.append("Name: ").append(location.getName())
                                .append('\n');
                        buffer.append("Desc: ").append(location.getDescription())
                                .append('\n');
                        buffer.append("Addr: ").append(location.getData
                                (MapLocation.LBS_LOCATION_STREET_ADDRESS_KEY))
                                .append('\n');
                        buffer.append("City: ").append(location.getData
                                (MapLocation.LBS_LOCATION_CITY_KEY))
                                .append('\n');
                        buffer.append("County: ").append(location.getData
                                (MapLocation.LBS_LOCATION_COUNTY_KEY))
                                .append('\n');
                        buffer.append("Zip: ").append(location.getData
                                (MapLocation.LBS_LOCATION_POSTAL_CODE_KEY))
                                .append('\n');
                    }
                    // Take control of the UI thread and display the location 
                    // information on the screen.
                    synchronized(UiApplication.getEventLock())
                    {
                        _resultsField.setText(buffer.toString());
                    }        
                }
            }
            public void requestFailure(ServerExchange exchange)
            {
                // Report the failure to the user.
            }
            public void requestHalted()
            {
                // Request was stopped.
            }   
        }
    }
}

Estas informações foram úteis? Gostaríamos de receber seus comentários.