Blackberry.location API not working correctly

守給你的承諾、 提交于 2020-01-06 08:50:33

问题


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


回答1:


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");
 }



回答2:


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.



来源:https://stackoverflow.com/questions/2876050/blackberry-location-api-not-working-correctly

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