Search code examples
apiblackberryblackberry-widgets

Blackberry.location API not working correctly


I am experimenting with making Blackberry widgets but having a little trouble.

My first trial involves displaying a button which, when clicked, calls a JavaScript function that should alert the phones latitude and longitude.

The function looks:

function whereAmI() {
var latitude = blackberry.location.latitude;
var longitude = blackberry.location.longitude;
alert("Lat: "+latitude+", Long: "+longitude);
}

But it only ever alerts "Lat: 0, Long: 0". I've checked and my GPS seems to be working ok.

I'm running OS 5.* on a Curve 8900.

Any help would be appreciated :)


Solution

  • I discovered that I wasn't signing my files properly - now that I have, everything works fine.

    For kaban:

          // called when location object changes
      function locationCB()
      {
         alert("Latitude "  + blackberry.location.latitude);
         alert("Longitude " + blackberry.location.longitude);
         return true;
     }
     // test to see if the blackberry location API is supported
     if( window.blackberry && blackberry.location.GPSSupported)
     {
           document.write("GPS Supported");
    
           // Set our call back function
           blackberry.location.onLocationUpdate("locationCB()");
    
           // set to Autonomous mode
           blackberry.location.setAidMode(2);
    
           //refresh the location
           blackberry.location.refreshLocation();
     }
     else
     {
       document.write("This Device doesn't support the Blackberry Location API");
     }