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

Native Development

Reply
Developer
Posts: 193
Registered: ‎12-29-2010
My Device: Bold 9900
My Carrier: Rogers

Faking GPS on the device

I was wondering if it's possible to inject coordinates into the GPS and have it fake a location.

 

I'd like to have this is a feature in my app. Any starting point to this?

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Faking GPS on the device

There's no built-in support for this sort of thing (yet) but generally one handles that sort of situation by writing a "wrapper" API that supports the feature. One option is just to have a mode switch, which you set to test mode when you want to retrieve fake locations, and normal mode when you're ready for release.

Obviously that's not quite as effective since requires you to "mock" more of the behaviour of the low-level APIs, but depending on what you're really testing (e.g. just higher level logic in your code?) it may be sufficient.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Faking GPS on the device

It's not possible and will never be possible.

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Faking GPS on the device


superdirt wrote:

It's not possible and will never be possible.


"Never"?  Why would you say that?


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Faking GPS on the device

Because it will never be possible to fake the GPS coordinates Smiley Happy

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Faking GPS on the device

That doesn't seem helpful. I already gave one approach to faking them. Others are certainly possible, technically.

If you don't have actual knowledge that BB has deliberately chosen never to release any mechanism that would allow developers to supply fake coordinates to their apps, for testing, then I don't see any point in your comment.

Note that the simulators already support just this, so it's not a stretch to think they may some day support a method of supplying "canned" data to apps on a device, for testing.

We're also expecting an API in future that will allow us to inject fake user events (e.g. keystrokes and touch events) to an app on the device, so again it seems completely within reason to think they might do that for other types of input as well, including GPS coordinates.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Faking GPS on the device


superdirt wrote:

Because it will never be possible to fake the GPS coordinates Smiley Happy


Why would you say that? You can do it in various simulators and Android devices already.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Faking GPS on the device

Why on Earth would BlackBerry allow the user to fake their device's GPS location? This would cause a load of problems for BlackBerry and the thousands of third party developers who depend on GPS location for security. 

 

To get the GPS coordinates of the device, you just ask for them. You are saying it is helpful to tell the device to use event injection coordinates bogus into the GPS layer, just so you can get them back again? I don't get the use case.

 

 

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Faking GPS on the device

You can do it in various simulators and Android devices already.

I'm not sure you understand the original request. The request is for how to fake a device's GPS coordiates as a feature in the app. If the only way to change the GPS coordinates is with a simulator, then this has nothing to app funtionality, it is simulator functionality.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Faking GPS on the device

[ Edited ]

superdirt wrote:

Why on Earth would BlackBerry allow the user to fake their device's GPS location? This would cause a load of problems for BlackBerry and the thousands of third party developers who depend on GPS location for security. 

 

To get the GPS coordinates of the device, you just ask for them. You are saying it is helpful to tell the device to use event injection coordinates bogus into the GPS layer, just so you can get them back again? I don't get the use case.


BB wouldn't let a user fake the location. You definitely didn't get the use case for this.  (Edit #2: I didn't get the OP's use case for this... I thought this was about faking data for test purposes.)

 

It's for testing your app, including automated testing.

 

Let me try a contrived example.  Say I'm writing a pedometer app which needs to be able to accurately measure the distance travelled. It incorporates an algorithm and, maybe, user interface elements designed to massage the stream of coordinates to eliminate "noise" such as outliers in the data. If my only method of testing this is to run the app and go outside for a jog, hoping that I'll encounter enough bad data to exercise the algorithm, then I'm not doing the best I could. Instead, I enable a development test mode which retrieves a predefined ("canned") stream of fake readings that I've preprocessed to include all the right types of bad input. I know exactly what the results should be (both the calculated distance and how things should appear in the UI), so as soon as I've run this I can check that the results are correct.

 

(Edited: to correct minor typo.)


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!