views:

40

answers:

1

I am trying to get the GPS location in a widget application on a blackberry, but the API always returns a latitude and longitude of 0,0.

Simulator: storm 2 (9550)/ bold(9700) and OS: 5.0/5.0

IDE:Eclipse

the html page code as below:

var modeCellsite   = 0;
var modeAssisted   = 1;
var modeAutonomous = 2;

function locationChanged()
{

    alert("Lat " + blackberry.location.latitude +
          " Lon " + blackberry.location.longitude +
          " Time " + blackberry.location.timestamp );
    return true;
}

if ( window.blackberry && blackberry.location.GPSSupported )
{
    var isUpdated = false;
    var theCount = 0;
    alert("Location tracking is supported");
    blackberry.location.onLocationUpdate("locationChanged()");
    blackberry.location.setAidMode(modeAutonomous);
    while ( theCount++ < 10 && !isUpdated )
        isUpdated = blackberry.location.refreshLocation();
}
else
{
    document.write("Location tracking is not supported");
}
A: 

Make sure you turned ON GPS in the SIM before running your widget.

For Example in the simulator goto:
    Simulate -> GPS Location...
    Under Route Click "add"
    Choice Random Route Generator
       Number of Legs 1000
       Travel Time 600
       click OK
    Click Play arrow
eSniff