Exemplo de código: Recuperar o tempo de viagem e a distância estimados

import net.rim.device.api.lbs.maps.MapDimensions;
import net.rim.device.api.lbs.maps.model.MapLocation;
import net.rim.device.api.lbs.maps.model.MapPoint;
import net.rim.device.api.lbs.maps.server.Geocoder;
import net.rim.device.api.lbs.maps.server.exchange.GeocodeExchange;
import net.rim.device.api.lbs.travel.TravelTime;
import net.rim.device.api.lbs.travel.TravelTimeEstimator;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.TextField;
import net.rim.device.api.ui.container.MainScreen;
import java.util.Vector;
import javax.microedition.location.Coordinates;
import javax.microedition.location.LocationProvider;
public final class TravelTimeDemo extends UiApplication
{
    public static void main(String[] args)
    {
        TravelTimeDemo theApp = new TravelTimeDemo();
        theApp.enterEventDispatcher();
    }
    public TravelTimeDemo()
    {
        pushScreen(new TravelTimeScreen());
    }
}
class TravelTimeScreen extends MainScreen implements FieldChangeListener
{
    private BasicEditField _destinationField;
    private LabelField _timeLabel;
    private LabelField _distanceLabel;
    private ButtonField travelButton;
    public TravelTimeScreen()
    {
        super(DEFAULT_CLOSE | DEFAULT_MENU);
        setTitle("Travel Time Demo");
        _destinationField = new BasicEditField("Destination: ", "", 500, 
                TextField.NO_NEWLINE);
        add(_destinationField);
        _timeLabel = new LabelField();
        add(_timeLabel);
        _distanceLabel = new LabelField();
        add(_distanceLabel);
        travelButton = new ButtonField("Get Travel Estimate",
                ButtonField.CONSUME_CLICK);
        travelButton.setChangeListener(this);
        add(travelButton);
    }
	   public void fieldChanged(final Field field, int context)
    {
        final String destination = _destinationField.getText();
        if ((destination == null) || (destination.length() == 0))
        {
            Dialog.alert("Destination field cannot be empty");
            return;
        }
        _timeLabel.setText("");
        _distanceLabel.setText("");
        Thread travelTimeThread = new Thread()
        {
            public void run()
            {
                try
                {
                    LocationProvider provider = LocationProvider.getInstance(null);
                    if (provider == null)
                    {
                        throw new IllegalStateException("No LocationProvider 
                                available");
                    }
                    Coordinates startCoords = provider.getLocation(-1)
                             .getQualifiedCoordinates();                   
                    MapPoint startPoint = new MapPoint(startCoords);                        
                    GeocodeExchange exchange = Geocoder.getInstance().geocode(null, 
                            destination, 
                            new MapDimensions(startPoint,480, 360, 5, 0), 0);                   
                    if(exchange.getExceptionList().size() < 0)
                    {
                        throw new IllegalStateException("Can't find end 
                                coordinates.");
                    }
                	   Vector results = exchange.getResults();
                	   MapLocation location = (MapLocation) results.elementAt(0);
                	   Coordinates endCoords = new Coordinates(location.getLat(), 
                            location.getLon(), 0);
                	   TravelTimeEstimator est = TravelTimeEstimator.getInstance();
                    final TravelTime travelTime = est.requestArrivalEstimate(
                            startCoords, endCoords, TravelTime.START_NOW, null);
                    showResults(travelTime);       
                }
                catch (final Exception e)
                {
                    Dialog.alert(e.getMessage());
                }
            }
        };
        travelTimeThread.start();
    }
    private void showResults(final TravelTime travelTime)
    {
        Application.getApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                long value = travelTime.getElapsedTime() / 1000;
                long seconds = value % 60;
                value /= 60;
                long minutes = value % 60;
                long hours = value / 60;
                StringBuffer buffer = new StringBuffer();
                buffer.append(hours);
                buffer.append(':');
                if (minutes < 10)
                {
                    buffer.append('0');
                }
                buffer.append(minutes);
                buffer.append(':');
                if (seconds < 10)
                {
                    buffer.append('0');
                }
                buffer.append(seconds);
                String msg = "Travel Time (h:m:s): " + buffer.toString();
                TravelTimeScreen.this._timeLabel.setText(msg);
                double distance = travelTime.getDistance() / 1000.0;
                msg = "Distance (km): " + Double.toString(distance);
                TravelTimeScreen.this._distanceLabel.setText(msg);
            }
        });
    }
}

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