Blackberry.location API not working correctly

2019-09-16 11:21发布

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 :)

2条回答
The star\"
2楼-- · 2019-09-16 11:52

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");
 }
查看更多
Viruses.
3楼-- · 2019-09-16 12:00

Does your widget have permission to use GPS? Go to Options->Applications, select your app, then "Edit Permissions". Make sure "Location Data" (in Connections) is set to Allow.

查看更多
登录 后发表回答