If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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 Contributor
Avtar_Guleria
Posts: 8
Registered: ‎06-15-2011
My Device: 9800
My Carrier: Vodafone

Geo location is not working in Blackberry webworks with 9800 simulator.

Hello,

 

I am creating a simple application which uses a   navigator.geolocation.getCurrentPosition(onSuccess, onError);
but it did not work.

 

I have already set the GPS location in simulator. when i check the same application using blackberry java script propertiies by

blackberry.location.GPSSupportedit returns true but blackberry.location.latitude and blackberry

.location.longitude it returns 0 for both the properties.

 

What should i do to use the geolocation Api in my phonegap project.

 

I am using blackberry os 6.0 and Eclipse plugin for webworks.

 

 

Thanks in advance.

 

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Geo location is not working in Blackberry webworks with 9800 simulator.

Have you checked out the followig tutorial?

 

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

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
Avtar_Guleria
Posts: 8
Registered: ‎06-15-2011
My Device: 9800
My Carrier: Vodafone

Re: Geo location is not working in Blackberry webworks with 9800 simulator.

Thank you, Tim Neil

 

That link ( tutorial ) really helps me a lot but the problem remains same. My application runs on firefox (in my computer ) successfully but in Blackberry Browser (of simulator) it is not running i think call to  geolocationSuccess(position) method is never made in BB browser as the alert message box in this method never popup. Following is my code.

*****************************************************************************************

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" charset="utf-8"
    src="phonegap.0.9.5.1.min.js"></script>
    <script type="text/javascript" src="html5_init.js"></script>
    <script>
    function getPosition()
    {
        try
        {
            //clearOutput();
            var options;
            //First test to see that the browser supports the Geolocation API
            if (navigator.geolocation !== null)
                {
                    alert("Retrieving Geographic information using default parameters");
                    navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, options);
                   
                 }
            else {
                alert("HTML5 geolocation is not supported.");
                 }
        }
        catch (e) {
            alert("exception (getPosition): " + e);
        }
    }
    function geolocationSuccess(position)
    {
        alert("Inside geoLocation");
        var coordinates = position.coords;
        var gpsTime = position.timestamp;
        displayLocationInfo(gpsTime, coordinates);
    }

    function geolocationError(posError)
    {
        try
        {
           
            if (posError)
            {
                switch(posError.code)
                {
                    case posError.TIMEOUT:
                        alert("TIMEOUT: " + posError.message);
                        break;
                    case posError.PERMISSION_DENIED:
                        alert("PERMISSION DENIED: " + posError.message);
                        break;
                    case posError.POSITION_UNAVAILABLE:
                        alert("POSITION UNAVAILABLE: " + posError.message);
                        break;
                    default:
                        alert("UNHANDLED MESSAGE CODE (" + posError.code + "): " + posError.message);
                        break;
                }
            }
        }
        catch (e) {
            errorMessage("Exception (geolocationError): " + e);
        }
    }
    function displayLocationInfo(time, coordinates)
    {
        try
        {
            var lat = coordinates.latitude;
            var lon = coordinates.longitude;
            var alt = coordinates.altitude;
            var acc = coordinates.accuracy;
            var altAcc = coordinates.altitudeAccuracy;
            var head = coordinates.heading;
            var speed = coordinates.speed;

            var locationInfo = "Current Location: \n";
            locationInfo += " Latitude: " + coordinates.latitude + "\n";
            locationInfo += " Longitude:  " + coordinates.longitude + "\n";
            locationInfo += " Altitude:  " + coordinates.altitude + "\n";
            locationInfo += " Accuracy:  " + coordinates.accuracy + "\n";
            locationInfo += " Altitude Accuracy:  " + coordinates.altitudeAccuracy + "\n";
            locationInfo += " Heading:  " + coordinates.heading + "\n";
            locationInfo += " Speed:  " + coordinates.speed + "\n";
            //displayOutput("<p>" + locationInfo + "</p>");
            alert(locationInfo);
        }
        catch (e) {
            alert("exception (displayLocationInfo): " + e);
        }
    }
       
   </script>
  
       <title>Gps Location</title>
  </head>
  <body bgcolor="silver" >
  <input type="button" Value="Get Gps Info" onclick="getPosition()">
  </body>
  </html>


**************************

Thanks in advance...  

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Geo location is not working in Blackberry webworks with 9800 simulator.

Which version of the BB6 OS is on the simulator?  There are some simulators out there where GPS emulation is just plain broken.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
Avtar_Guleria
Posts: 8
Registered: ‎06-15-2011
My Device: 9800
My Carrier: Vodafone

Re: Geo location is not working in Blackberry webworks with 9800 simulator.

Thankyou, Tim Neil 

 

My problem is solved i have run the code with another simulator. 9330 (6.0.0.436). It gets the Gps location but sometime it shows error that

Unsupported RadioGetGprs api has been called and then it does not run..

 

Otherwise the code is running.

 

Again Thanks a lot for your support.

Please use plain text.