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
Contributor
Posts: 10
Registered: ‎04-20-2011
My Device: Storm
My Carrier: Verizon

JavaScript Widget Extension to get Geo location coordinates

Hi,

 

 I am trying to create one widget java script extension jar and trying to use in the webworks application.

 

I am getting error while building and running the web works project using that jar .

 

 

[INFO]       Parsing command line options
[INFO]       Parsing bbwp.properties
[INFO]       Validating application archive
[INFO]       Parsing config.xml 
[WARNING]   Failed to find the <author> element
[INFO]       Populating application source
[INFO]       Compiling BlackBerry WebWorks application
C:\Users\Moofwd\AppData\Local\Temp\widgetGen.11403752381303768285734.tmp\extension\mypackage\GeoLocationScrFunction.java:9: cannot find symbol
symbol  : class LocationInfo
location: package net.rim.device.api.gps
import net.rim.device.api.gps.LocationInfo;
                             ^
C:\Users\Moofwd\AppData\Local\Temp\widgetGen.11403752381303768285734.tmp\extension\mypackage\GeoLocationScrFunction.java:22: cannot find symbol
symbol  : variable LocationInfo
location: class mypackage.GeoLocationScrFunction
            BlackBerryCriteria myCriteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE);
                                                                   ^
C:\Users\Moofwd\AppData\Local\Temp\widgetGen.11403752381303768285734.tmp\extension\mypackage\GeoLocationScrFunction.java:22: internal error; cannot instantiate BlackBerryCriteria(int) at net.rim.device.api.gps.BlackBerryCriteria to ()
            BlackBerryCriteria myCriteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE);
                                            ^
3 errors
Error!: Error: java compiler failed: javac -source 1.3 -target 1.3 -nowarn -g -O -d C:\Users\Moofwd\AppData\Local\Temp\rapc_107e24c3.dir ...
[ERROR]     RAPC exception occurred
BUILD EXITED WITH 1 ERROR
************************************

[INFO]       Parsing command line options[INFO]       Parsing bbwp.properties[INFO]       Validating application archive[INFO]       Parsing config.xml [WARNING]   Failed to find the <author> element[INFO]       Populating application source[INFO]       Compiling BlackBerry WebWorks applicationC:\Users\Moofwd\AppData\Local\Temp\widgetGen.11403752381303768285734.tmp\extension\mypackage\GeoLocationScrFunction.java:9: cannot find symbolsymbol  : class LocationInfolocation: package net.rim.device.api.gpsimport net.rim.device.api.gps.LocationInfo;                             ^C:\Users\Moofwd\AppData\Local\Temp\widgetGen.11403752381303768285734.tmp\extension\mypackage\GeoLocationScrFunction.java:22: cannot find symbolsymbol  : variable LocationInfolocation: class mypackage.GeoLocationScrFunction            BlackBerryCriteria myCriteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE);                                                                   ^C:\Users\Moofwd\AppData\Local\Temp\widgetGen.11403752381303768285734.tmp\extension\mypackage\GeoLocationScrFunction.java:22: internal error; cannot instantiate BlackBerryCriteria(int) at net.rim.device.api.gps.BlackBerryCriteria to ()            BlackBerryCriteria myCriteria = new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE);                                            ^3 errorsError!: Error: java compiler failed: javac -source 1.3 -target 1.3 -nowarn -g -O -d C:\Users\Moofwd\AppData\Local\Temp\rapc_107e24c3.dir ...[ERROR]     RAPC exception occurredBUILD EXITED WITH 1 ERROR************************************

 

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

Re: JavaScript Widget Extension to get Geo location coordinates

Hi There,

 

Before we get into diagnosing the issue.  I'm curious on your need to bulild a geolocation extension when it is supported natively in the WebWorks framework via the built in functionality of the browser.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 10
Registered: ‎04-20-2011
My Device: Storm
My Carrier: Verizon

Re: JavaScript Widget Extension to get Geo location coordinates

Neil,

 

   This is my requirement. 1. I have created one application which is using HTML 5 (Gears js) to get the geo location and its working fine as web application (through BB Browser) and also as Web works application for smart phones But its not working in the Playbook as web works application (its been pointed in the known issue of the release).

 

So i was thinking to create a widget extension using RIM apis to get coordinates as java script in the webworks application for playbook as well as smart phone. i believe this would be working.so i tried but it was giving error while building the webworks application. 

 

 

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

Re: JavaScript Widget Extension to get Geo location coordinates

JavaScript extensions written in Java will only work on the BlackBerry Smartphone.  There is a work around that involves adding one line to a file in the WebWorks SDK for PlayBook to activate GPS inside a WebWorks app.

 

This setting was something that came up late in the release cycle where we were not able to configure it using config.xml settings so it is something that will have to be manually configured in the SDK.

 

A KB article is being drafted that will explain how to make this change to enable GPS in your app for PlayBook

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 10
Registered: ‎04-20-2011
My Device: Storm
My Carrier: Verizon

Re: JavaScript Widget Extension to get Geo location coordinates

You said " Java script extension written in Java wil work on Smartphones rite.

 

Please share the KB article 

 

Then i was getting the error . Let me share my code , Please help to fix the issue.

 

WidgetExtension class

 

 

public class GeoWidgetExtension implements WidgetExtension {
 public String[] getFeatureList() {
 String[] result = new String[1];
      result[0] = "geo.points";
      return result;
 }
 public void loadFeature(String feature, String version, Document doc,
 ScriptEngine scriptEngine) throws Exception {
 if (feature == "geo.points") {
         scriptEngine.addExtension("geo.points", new GeoLocationScriptable());
      }
 }
 public void register(WidgetConfig widgetConfig, BrowserField browserField) {
 // TODO Auto-generated method stub
 }
 public void unloadFeatures(Document doc) {
 // TODO Auto-generated method stub
 }
}

 

public class GeoWidgetExtension implements WidgetExtension {
public String[] getFeatureList() { String[] result = new String[1];      result[0] = "geo.points";      return result; }
public void loadFeature(String feature, String version, Document doc, ScriptEngine scriptEngine) throws Exception { if (feature == "geo.points") {         scriptEngine.addExtension("geo.points", new GeoLocationScriptable());      }
}
public void register(WidgetConfig widgetConfig, BrowserField browserField) { // TODO Auto-generated method stub
}
public void unloadFeatures(Document doc) { // TODO Auto-generated method stub
}
}

 

Scriptable class:

 

 

public class GeoLocationScriptable extends Scriptable{

 public static final String coordinates = "coordinates";

  

   private GeoLocationScrFunction geoLocationFn;

 

    public GeoLocationScriptable() {

 // TODO Auto-generated constructor stub

     this.geoLocationFn = new GeoLocationScrFunction();

   

 }

   // The getField() function is called when the 

   //  dot '.' extender is used on your JavaScript object.

   public Object getField(String name) throws Exception {

      if (name.equals(coordinates)) {

         return geoLocationFn;

      } 

      return super.getField(name);

   }

 

}

 

 

Script Function:

 

 

public class GeoLocationScrFunction extends ScriptableFunction{

 

 public Object invoke(Object obj, Object[] args) throws Exception

   {

     

 String s[] = new String[2] ;

 try

        {

            BlackBerryCriteria myCriteria = new BlackBerryCriteria(9);

            try

            {

                BlackBerryLocationProvider myProvider = (BlackBerryLocationProvider)LocationProvider.getInstance(myCriteria);

                try

                {

                    BlackBerryLocation myLocation = (BlackBerryLocation)myProvider.getLocation(300);

                    s[0]=String.valueOf(myLocation.getQualifiedCoordinates().getLongitude());

                    s[1]=String.valueOf(myLocation.getQualifiedCoordinates().getLatitude());

 

                }

                catch (InterruptedException e)

                {

                    showException(e);

                }

                catch (LocationException e)

                {

                    showException(e);

                }

            }

            catch (LocationException e)

            {

                showException(e);

            }

       } 

       catch (UnsupportedOperationException e) 

       {

           showException(e);

       }

 

   return s;

   }

 

 

private void showException(final Exception e) 

{

    Application.getApplication().invokeLater(new Runnable() 

    {

        public void run() 

        {

            Dialog.alert(e.getMessage());

        }

    });

}

}

 

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

Re: JavaScript Widget Extension to get Geo location coordinates

Yes you can create a Java extension on the Smartphone.  However for GPS this API is already built in.. Are you experiencing problems with this existing API and desire to build your own?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 10
Registered: ‎04-20-2011
My Device: Storm
My Carrier: Verizon

Re: JavaScript Widget Extension to get Geo location coordinates

Can you please share GPS API for smart phone links.i have seen to invoke maps api.but i could nt see the fetching geo location coordinates.

 

 

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

Re: JavaScript Widget Extension to get Geo location coordinates

This tutorial should help:

 

http://supportforums.blackberry.com/t5/Web-Development/Using-HTML5-Geolocation-in-your-Web-or-BlackB...

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 10
Registered: ‎04-20-2011
My Device: Storm
My Carrier: Verizon

Re: JavaScript Widget Extension to get Geo location coordinates

Thanks Neil. Actually i had developed the application by referring this tutorial to invoke maps to fetch the current location using HTML 5 geo location api.and its working in Browser as well as webworks application for smart phones.

 

Please share the KB article to geo location for playbook.

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

Re: JavaScript Widget Extension to get Geo location coordinates

Once the KB article is uploaded for PlayBook we will post a link in the forums to it as well

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter