Blackberry - change latitude and longitude on the device to test app

雨燕双飞 提交于 2019-12-01 02:20:16

Inside GPS mockup

If you have access to your application code, you can always create a mockup implementation for LocationProvider so it will read location and speed data from file or RecordStore and return it as a Location, something like

public class MockupLocationProvider extends LocationProvider {

    public MockupLocationProvider() {
        //prepare a file or RecordStore with locations here
    }

    public Location getLocation(int arg0) throws LocationException,
            InterruptedException {      
        //read data from file or RecordStore
        double latitude = 321;
        double longitude = 34;
        float altitude = 21;
        //create and return location
        Location result = new GPSLocation(latitude, 
            longitude, altitude);       
        return result;
    }

    public int getState() {
        // mockup location provider always available 
        return LocationProvider.AVAILABLE;
    }

    public void reset() {
        // your code        
    }

    public void setLocationListener(LocationListener listener, 
            int interval, int timeout, int maxAge) {
        // your code        
    }
}

and mockup for your Location

public class GPSLocation extends Location {    
    double _latitude, _longitude;
    float _altitude, _horAcc = 0, _verAcc = 0, _speed;
    public GPSLocation(double lat, double lon, float alt) {
        init(lat, lon, alt);
    }    
    public GPSLocation(double lat, double lon, float alt, float spd) {
        init(lat, lon, alt);
        _speed = spd;
    }    
    private void init(double lat, double lon, float alt) {
        _latitude = lat;
        _longitude = lon;
        _altitude = alt;
    }    
    public QualifiedCoordinates getQualifiedCoordinates() {
        QualifiedCoordinates c = new QualifiedCoordinates(_latitude,
                _longitude, _altitude, _horAcc, _verAcc);
        return c;
    }    
    public float getSpeed() {
        return _speed;
    }    
    public String toString() {
        String result = "Lat:" + String.valueOf(_latitude) + "|Lon:"
                + String.valueOf(_longitude) + "|Alt:"
                + String.valueOf(_altitude);
        return result;
    }
}

Then somewhere on the screen

    MockupLocationProvider gpsProvider = new MockupLocationProvider();
    GPSLocation loc = (GPSLocation)gpsProvider.getLocation(0);
    add(new RichTextField(loc.toString())); 

Outside GPS mockup

Another option is to generally mockup GPS signals.
Steps are:

  • configure device gps receiver for bluetooth (for ex.)
  • setup some opensource gps server on your desktop to produce location data over bluetooth
  • change configuration/code of gps server to mockup location data

Other options

There is a possibility to uncontrolled change of location gps data by shielding gps receiver with some radio-material (like alluminium foil or so) :)

In the BB simulator you can go to Simulate > GPS Location. Click the Add button and enter in a name, latitude and longitude. Click save and the simulator will start feeding your new location to the apps. Note that whatever location is displayed in the drop down is the one that will be reported by the simulator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!