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
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

LocationPicker EnterLocatinPicker never seems to return a Location

I would like to allow users to select an address just by typing in the address details.  I have looked at LocationPicker and the various classes, and EnterLocationPicker seems to fit the requirements.  However I can't get it work.

 

From my reading of the documentation and reviewing the sample app, I pretty much just need to define my Location Picker, allow it to show(), the the listener's locationPicker will be called.  This does seem to be correct in my testing, but I can not get ago-ordinates from the locaiton passed in. 

 

This also seems to be the problem with the sample provided when being used in the same way.  In my testing on a number of devices, it never finds a real GPS location for anything I ask it about.   

 

Has anyone got the Enter Location option working?  Or does it not actually return the GPS location for the user specified. 

 

 

Retired
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: LocationPicker EnterLocatinPicker never seems to return a Location

Hey Peter,

Can you share some code snippet? You can send me this offline as well if you dont want to share the code in public.

 

Shadid

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: LocationPicker EnterLocationPicker never seems to return a Location

Thanks for looking.  Here is some code.

 

Pretty sure there is a bug in my code or I have misunderstood.  I've been through the JavaDocs and this seems to be the appropriate way of doing this but likely I have missed something.

 

Note that there are two tests, depending on getInstance() parameter. 

 

Testing this in the Simulator the top button caused an "Application is not responding" Exception.  The bottom button immediately bounced in LocationUpdated() without actually getting the GPS location. 

 

I've not tested on device, the Signing Server does not want to talk to me. 

 

Any help gratefully accepted....  TIA

 

import javax.microedition.location.*;

import java.util.Enumeration;

import net.rim.blackberry.api.invoke.*;
import net.rim.device.api.gps.*;
import net.rim.device.api.lbs.picker.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;

import net.rim.device.api.util.Arrays;

/**
 * A sample Screen to test the EnterLocationPicker API
 */
public class EnterLocationPickerScreen extends MainScreen implements LocationPicker.Listener, FieldChangeListener {

    private LocationPicker.Picker _searchLocationPicker = EnterLocationPicker.getInstance(true);
    private LocationPicker.Picker _searchLocationPicker2 = EnterLocationPicker.getInstance(false);
    private ButtonField _buttonField;
    private ButtonField _buttonField2;
    private LabelField _nameLabel;               
    private LabelField _descLabel;
    private LabelField _coordLabel;
       
    /**
    * Creates a new EnterLocationPickerScreeb object
    */
    public EnterLocationPickerScreen() {
        // Initialize screen
        setTitle("Enter Location");
        _buttonField = new ButtonField("Choose location (true)", ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
        _buttonField.setChangeListener(this);
        add(_buttonField);
        _buttonField2 = new ButtonField("Choose location (false)", ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
        _buttonField2.setChangeListener(this);
        add(_buttonField2);
        _nameLabel = new LabelField();
        _descLabel = new LabelField();
        _coordLabel = new LabelField();
        add(_nameLabel);
        add(_descLabel);
        add(_coordLabel);
    }      

    /**
    * @see LocationPicker.Listener#locationPicked(LocationPicker.Picker, Landmark)
    */
    public void locationPicked (LocationPicker.Picker picker, Landmark location) {
        if(location != null) {
            _nameLabel.setText("Location name: " + location.getName());
            _descLabel.setText("Description: " + location.getDescription());
            QualifiedCoordinates coordinates = location.getQualifiedCoordinates();
            if(coordinates != null) {
                StringBuffer buff = new StringBuffer("Coordinates: ");
                double latitude = coordinates.getLatitude();
                double longitude = coordinates.getLongitude();
                buff.append("Latitude:");
                buff.append(latitude);
                buff.append(", Longitude: ");
                buff.append(longitude);                       
                _coordLabel.setText(buff.toString());                   
            }
        } else {
            _nameLabel.setText("Location Not found");
            _descLabel.setText(null);
            _coordLabel.setText(null);
        }
    }
       
       
    /**
    * @see FieldChangeListener#fieldChanged(Field, int)
    */
    public void fieldChanged(Field field, int context) {
        if(field == _buttonField) {
            // Display the location picker
            LocationPicker getLocation = LocationPicker.getInstance( new LocationPicker.Picker [] {_searchLocationPicker} );
            getLocation.setFreeTextSearch(true);
            getLocation.setListener(this);
            getLocation.show();
        } else
        if ( field == _buttonField2 ) {
            LocationPicker getLocation = LocationPicker.getInstance( new LocationPicker.Picker [] {_searchLocationPicker2} );
            getLocation.setFreeTextSearch(true);
            getLocation.setListener(this);
            getLocation.show();
        }
    } 

Retired
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: LocationPicker EnterLocationPicker never seems to return a Location

Peter,

I dont see anything wrong with your code. I did compile your code as is and ran it on my 9810. It works as expected. When I select the "true" button, it returns the entered address as well as the coordinate. The false button returns the entered address.

 

There could be a few reasons why this might fail for you.

1. The address you are entering, is not in our database for geocoding.

2. You dont have locations ervices enabled.

3. I am not sure about this, but having a blackberry data plan might be required on the device for this to work.

 

Shadid

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: LocationPicker EnterLocationPicker never seems to return a Location

[ Edited ]

Thanks for running the test Shaque.

 

Can you please tell me an address that you know works.  Also can you tell me the OS of the phone you are using.

 

I have been testing on phones with BB data plan and thought I had enabled location services.  . 

 

Would you expect this code to work on a Simulator?

Retired
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: LocationPicker EnterLocationPicker never seems to return a Location

Peter,

I dont expect it to work on the simulator since there are some provisioning involved here. That said, I never actually tried it on a simulator.

 

I tried my work address:

619 Kumpf Drive

Waterloo ON

 

Device: 9810

OS: 7.1.0.392