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
Trusted Contributor
sergiosandoval
Posts: 132
Registered: ‎02-17-2012
My Device: Bold 9900
My Carrier: AT&T

Ha Any one worked with speed??

Have any one work with speed? with the geo.js? i have some questions!

 

Such as how do you get it to update every mili second?- if posible

 

Also how to not have a button to "get cordinates"

 

 

I ve been messing with the "Helloworldtutorialassets" for the pb.

 

I can get it to tell me the speed BUT I have to click on the button ever time and its not every fast. It takes alot fo time to get  speed or cordinates.

 

 

Thanks in advanced

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Ha Any one worked with speed??

Hello there,

 

Just to confirm, are you referring to this sample here?

https://bdsc.webapps.blackberry.com/html5/documentation/ww_tutorials/Tutorial_Create_first_app_intro...

 

The noted sample leverages an onClick event to trigger getPosition. If we look into geo.js, we see that getPosition is defined as follows:

 

function getPosition(params) {
    try {
        clearOutput();
		
        //First test to verify that the browser supports the Geolocation API
        if (navigator.geolocation !== null) {
            //Configure optional parameters
            var options;
            if (params) {
                options = eval("options = " + params + ";");
            } else {
                // Uncomment the following line to retrieve the most accurate coordinates available
                // options = { enableHighAccuracy : true, timeout : 60000, maximumAge : 0 };
            }

            navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, options);
        } else {
            errorMessage("HTML5 geolocation is not supported.");
        }
    } catch (e) {
        errorMessage("exception (getPosition): " + e);
    }
}

The "important" part is our call to navigator.geolocation.getCurrentPosition. This is where we actually get the coordinates, which was initiated by the click event.

 

Alternatively, you can leverage setTimeout to repeatedly make a call to get the current position, or you can register a position listener via watchPosition:

https://bdsc.webapps.blackberry.com/html5/apis/navigator.geolocation.html#.watchPosition

 

You can configure setTimeout to fire every millisecond, however I would argue that there wouldn't be very many scenarios that would need that much data being processed, the impact on battery life will likely be noticeable, and there may end up being a backlog of requests as I'm not sure a device could process everything that quickly.

 

Leveraging watchPosition will allow you to receive updates only when the position changes, thus minimizing on unnecessary checks.

 

Let me know if you have any questions.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Developer
nunodonato
Posts: 313
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Ha Any one worked with speed??

[ Edited ]

hi Erik,

What would be the hit in battery-life of having a background listener with that geolocation check to run every 5min or so? Significant?

Nuno
theBBthing.wordpress.com - my BlackBerry development blog: news, tips and tutorials
bitoutsidethebox.com - re-imagining digital solutions


Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Ha Any one worked with speed??

Once every 5 minutes would have a minimal impact. If you are using cellsite, that impact is lessened.

 

The largest battery cost related to GPS is when you are actually using the GPS chip on the device to get a high accuracy position fix and that chip has to go from cold (not been used in a while) to hot (active.) During that transition is where the scan of the sky / search for satellites occurs, among other things that really eat up battery.

 

I am not 100% certain about the WebWorks timeouts, but for instance, on the Java side for frequent GPS fixes it is less costly to get a fix every 8 seconds than it is every 14 seconds, because the GPS timeout (i.e. hot to cold) is somewhere around 10 seconds. Meaning a GPS fix every 14 seconds requires a full re-scan of the sky each time.

 

My primary recommendation would be to simply consider what the real requirements for a GPS fix are and work within those constraints. If you need a fix every 5 minutes, or 1 minute, or 5 seconds, so be it. If you're transferring that data somewhere, it mighit make more sense to do it in batches (i.e. once every hour) as opposed to firing up a new HTTP connection each time. And other considerations.

 

Sorry, I ran on a little. So to answer your question, once every 5 minutes would be fairly negligible. Even once every 5-10 seconds is still...not the worst...as long as it is justified and optimization is occurring (i.e. you're not just getting the location for the sake of getting a location.) But trying to fit a fix in every 1 millisecond would definitely start to cause both functional and battery issues.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Trusted Contributor
sergiosandoval
Posts: 132
Registered: ‎02-17-2012
My Device: Bold 9900
My Carrier: AT&T

Re: Ha Any one worked with speed??

Thanks for the reply Erik. What im trying to do is make a speedometter app which is why you. Want it to update every miliseconds. but now that you say that having it update every milisecond would kill the battery. Makes me not want to continue with this app. 

 

Also yes i was talking about the sample you posted.

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Ha Any one worked with speed??

Hi there,

 

Well that doesn't necessarily mean you need to drop this project completely. If you look at the majority of GPS driving devices out there, they don't do an immediate real-time update either. Most of them will update your speed every 1-2 seconds, which is much more reasonable than every millisecond.

 

If you're looking to recreate something like a speedometer in a car, you won't get that real-time accuracy with any GPS-based application. But there are certainly ways to get data often, and provide that to the user in a meaningful way.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Trusted Contributor
sergiosandoval
Posts: 132
Registered: ‎02-17-2012
My Device: Bold 9900
My Carrier: AT&T

Re: Ha Any one worked with speed??

Alight. so your saying that i should implement that into my geo.js file? or xml?

 

 

function(position : Position)

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Ha Any one worked with speed??

Hi there,

 

It depends on the sort of trigger you want for tracking GPS. In the sample, they use a click event on a button to trigger one location fix. You could also register an event listener to automatically get a location fix when the application starts. For instance:

 

window.addEventListener("DOMContentLoaded", ready, false);

 Then, when the DOMContentLoaded event is triggered (i.e. the document is fully loaded) the function ready would be triggered. From there, we have a few options. One might be:

 

function getLocationFix() {
    // Start a new timer to get a location fix in 3000 milliseconds.
    setTimeout("getLocationFix();", 3000);

    /* TODO: Get the new location fix here and do something. */
}

function ready() {
    // Don't need this listener anymore.
    window.removeEventListener("DOMContentLoaded", ready, false);

    /* TODO: Get the initial GPS location fix here. */

    // Start getting a location fix every 3000 milliseconds.
    setTimeout("getLocationFix();", 3000);
}

Another option would be to leverage the watchPosition API which triggers an event when the position changes:

https://bdsc.webapps.blackberry.com/html5/apis/navigator.geolocation.html#.watchPosition

 

These sort of JavaScript changes would best be implemented into geo.js.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Trusted Contributor
sergiosandoval
Posts: 132
Registered: ‎02-17-2012
My Device: Bold 9900
My Carrier: AT&T

Re: Ha Any one worked with speed??

Sweet thanks! im in the middle of moving ATM but when i get settled in ill give it a try. Silicon Valley here i come!

Please use plain text.