Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 13
Registered: ‎04-27-2010
My Device: Curve 8900
Accepted Solution

Problem with blackberry.location.longitude and latitude

[ Edited ]

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.

New Developer
Posts: 13
Registered: ‎04-27-2010
My Device: Curve 8900

Re: Problem with blackberry.location.longitude and latitude

Nobody have any ideas yet?  Someone suggested checking the permissions for the widget and they are all set to allow and still no joy.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Problem with blackberry.location.longitude and latitude

Hi There,

 

Which GPS JavaScript calls are you using?

- blackberry.location 

http://www.blackberry.com/developers/docs/widgetapi/blackberry.location.html

- Gears GeoLocation

http://www.blackberry.com/developers/docs/widgetapi/google.gears.geolocation.html

 

You typically need to place a listener for the coordinates via a callback because it can take some time to acquire a GPS fix.

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 13
Registered: ‎04-27-2010
My Device: Curve 8900

Re: Problem with blackberry.location.longitude and latitude

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

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Problem with blackberry.location.longitude and latitude

Try changing your <access> element to the following:

 

<access uri="http://development.sinaesthesia.co.uk" subdomains="true" />

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 13
Registered: ‎04-27-2010
My Device: Curve 8900

Re: Problem with blackberry.location.longitude and latitude

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. 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Problem with blackberry.location.longitude and latitude

If you use the signing option of the bbwp.exe it will sign both the OTAInstall and StandardInstall files.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Developer
Posts: 13
Registered: ‎04-27-2010
My Device: Curve 8900

Re: Problem with blackberry.location.longitude and latitude

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.