05-20-2010 11:43 AM - edited 05-20-2010 11:51 AM
My first, very basic test widget has a button which, when clicked, should alert the phone's latitude and longitude, but both values are 0, for some reason. I checked on the phone that the GPS is working fine and it gives me my lat and long, but I can't seem to get the real values in my script. I'm running version 5 of the OS on a Curve 8900.
Solved! Go to Solution.
05-23-2010 03:31 PM
Nobody have any ideas yet? Someone suggested checking the permissions for the widget and they are all set to allow and still no joy.
05-24-2010 07:53 AM
Hi There,
Which GPS JavaScript calls are you using?
- blackberry.location
http://www.blackberry.com/developers/docs/widgetap
- Gears GeoLocation
http://www.blackberry.com/developers/docs/widgetap
You typically need to place a listener for the coordinates via a callback because it can take some time to acquire a GPS fix.
05-24-2010 09:43 AM
Thanks, tneil. I tried running the sample script, but I'm having some problems.
If you don't mind, I'll post everything and let you see if you can spot any glaring errors.
Here is my config.xml:
<?xml version="1.0" encoding="utf-8" ?> <widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0"> <name>Where Am I?</name> <description>A sample of basic Widget API usage</description> <author href="http://sinaesthesia.co.uk/" rim:copyright="no copyright" email = "jonathon@sinaesthesia.co.uk"> Jonathon Scott - sinaesthesia </author> <license href="http://www.license.com">This is a sample license</license> <content src="index.html" /> <feature id="blackberry.system" /> <feature id="blackberry.identity" /> <feature id="blackberry.location" /> <feature id="blackberry.invoke.CalendarArguments" /> <feature id="blackberry.invoke" /> <access uri="http://development.sinaesthesia.co.uk/whereami.js" subdomains="true" /> </widget>
index.html:
<html> <head> <title>Location API</title> <script type="text/javascript" src="http://development.sinaesthesia.co.uk/whereami.js"></script> </head> <body> <p> Widget API Basic Sample</p> <div> <input id="load" type="button" value="Where am i?" onclick="whereAmI()" /> </div> </body> </html>
whereami.js (saved at development.sinaesthesia.co.uk/whereami.js):
// 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");
}
I've tried wrapping the main portion of the javascript in a function to be called when the button is pressed, I've tried changing whereami.js to a simple alert, either running immediately or when the button is pressed, and nothing. It seems that the remote js is not running.
If you have the time, I hope you can give it a once-over.
Many thanks,
Jonathon
05-24-2010 10:07 PM
Try changing your <access> element to the following:
<access uri="http://development.sinaesthesia.co.uk" subdomains="true" />
05-25-2010 01:53 PM
Thank you very much, tneil - everything is working well now.
A follow up question, but not worth putting in a new thread:
When I use bbwp.exe, my files are output to the folders OTAInstall and StandardInstall. This means I need to collate the files into a folder before signing/loading, right? I have found things don't work unless I do this. I am using Allway Sync to make the process of file management easier (much faster than manually doing it), but is this how it's supposed to work? I tried running bbwp in the bin folder and it doesn't work for some reason.
It's not important, I'm quite happy with the Allway Sync solution and recommend it. You set up one job to move the zip file from the folder you're saving your config.xml, index.html and .js files in to the folder with bbwp.exe (makes the command line easier, rather than having to type the complete path), compile the widget, and have two jobs to collate the OTA and Standard Install folders into one, sign the widget and then load it.
05-25-2010 02:34 PM
If you use the signing option of the bbwp.exe it will sign both the OTAInstall and StandardInstall files.
05-25-2010 06:28 PM
I didn't even see the option to sign at the same time as compiling - or for modifying the output folder! Both have saved me a lot of time - thanks for the heads up and for nursing me through these basics.