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: 23
Registered: ‎09-10-2009
My Device: Not Specified

Capturing GPS coordinates while in browser

While viewing a broswer page, I want to click a rado button and capture the coordinates of the GPS,and bring them into the web form.

 

How can I caputre the GPS coordinates?

Developer
Posts: 395
Registered: ‎12-18-2008
My Device: BlackBerry Torch 9800
My Carrier: AT&T

Re: Capturing GPS coordinates while in browser

Use the JavaScript BlackBerry.Location object. Take a look in the Browser JavaScript guide.
New Developer
Posts: 23
Registered: ‎09-10-2009
My Device: Not Specified

Re: Capturing GPS coordinates while in browser

Thanks for the reply.  I am very new to BlackBerry development, so if you could point me in the right direction, even with some samples, it would be very much appreciated.

Developer
Posts: 395
Registered: ‎12-18-2008
My Device: BlackBerry Torch 9800
My Carrier: AT&T

Re: Capturing GPS coordinates while in browser

The first place to start is the documentation - it includes information about the capabilities of the browser (including GPS Support) and sample code for implementing it.  If you look there, you'll find exactly what you're looking for. Go to the BlackBerry Developers web site (www.blackberry.com/developers), select Developer Documentation then Browser - read through the Browser Content Developer Guide (last published for BlackBerry Device Software 4.3 - now called the Fundamentals guide) and the JavaScript Guides - both located in the same place:

 

http://docs.blackberry.com/en/developers/subcategories/?userType=21&category=BlackBerry+Browser

 

There's also this really cool book being released in 11 days called BlackBerry Development Fundamentals - it's a book designed for brand new BlackBery developers. It contains everything you need to get started with BlackBerry development - including the answer to this post (how to access location information in the browser with sample code).

 

 

 

New Developer
Posts: 23
Registered: ‎09-10-2009
My Device: Not Specified

Re: Capturing GPS coordinates while in browser

Thanks again, that was extremely helpful.  I found everything except sample code where it is implemented.  If you could point me towards that it would be very much appreciated.
Developer
Posts: 395
Registered: ‎12-18-2008
My Device: BlackBerry Torch 9800
My Carrier: AT&T

Re: Capturing GPS coordinates while in browser

I'ts just JavaScript. You have a Location Object (blackberry.location) plus properties and methods you can access within that object.

 

From chapter 9 of BlackBerry Development Fundamentals: 

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> </HEAD> <BODY> <SCRIPT type="text/javascript"> <!-- if(blackberry.location.GPSSupported) { blackberry.location.refreshLocation(); document.write("The client BlackBerry device is currently located at " + blackberry.location.latitude + " degrees latitude and " + blackberry.location.longitude + " degrees longitude."); } //--> </SCRIPT> <NOSCRIPT>Sorry, this browser does not support JavaScript!</NOSCRIPT> </BODY> </HTML>

 

 

 

New Developer
Posts: 23
Registered: ‎09-10-2009
My Device: Not Specified

Re: Capturing GPS coordinates while in browser

I get "0" for my longitude and latitude.  I have the location finder enabled in the BlackBerry, so what am I doing wrong?

New Developer
Posts: 43
Registered: ‎07-29-2008
My Device: Not Specified

Re: Capturing GPS coordinates while in browser

Are you using the simulator or a physical device? Some simulators return 0 for longitude and latitude until you change the coordinates. Enable the JavaScript Location API in the browser settings.

New Developer
Posts: 23
Registered: ‎09-10-2009
My Device: Not Specified

Re: Capturing GPS coordinates while in browser

It is a physical device (my tour), and I do have JavaScript Location API running in the browser settings.  Any other ideas?

Developer
Posts: 395
Registered: ‎12-18-2008
My Device: BlackBerry Torch 9800
My Carrier: AT&T

Re: Capturing GPS coordinates while in browser

Verizon Tour? Doesn't Verizon disable GPS on BlackBerry devices and force you to purchase their location services? That is the way it was on the 8830, the device had GPS hardware, the carrier disabled it.