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
kks
New Contributor
Posts: 7
Registered: ‎03-12-2010
My Device: 9000
My Carrier: att

Geo-Location JS API not working on BB

Hi,

 

I am trying to use geo-location-javascript API (http://code.google.com/p/geo-location-javascript) to get my location coordinates. I am using BB 8820 simulator and I have developed a simple web application, using Eclipse IDE, that just returns the lattitude and longitude coordinates.  When I tried it on Eclipse's in-built browser, it gives me the coordinates but when I hit the same application from BB simulator's browser, it only displays the home page of my application.

 

I also tried BB Location API but it returns zero values for latitude and longitude. What does this signify?

 

 

I have enable JS in the BB simulator browser but still it doesnot give the required result. Kindly help me what needs to be done to resolve this issue.

 

 

 

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

Re: Geo-Location JS API not working on BB

Which version of the BlackBerry operating system do you have on the 8820 simulator?  Gears Geolocation is only available on version 5.0 of the BlackBerry OS.

 

Can you post your JavaScript that you are using when trying the blackberry.location JavaScript objects.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
kks
New Contributor
Posts: 7
Registered: ‎03-12-2010
My Device: 9000
My Carrier: att

Re: Geo-Location JS API not working on BB

8820 simulator had OS version 4.5. I did not pay attention to this detail while installing it. Thanks for pointing out. Now, I am using BlackBerry simulator 9000 (OS version 5.0). I have tried Geo-Location JS API and BlackBerry-Location API, both are resulting in zero latitude and longitude.

 

Following is the JS script that I used from the tutorial of creating web application:

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Eclipse Plug-in Tutorial</title>
<script type="text/javascript">
function updateDate() {
var date = new Date();
document.getElementById("divDate").innerHTML = date.toDateString();
}
function locationUpdated() {//display the new location
var latitude = "unknown";
var longitude = "unknown";
var pf = navigator.platform;
if (pf == "BlackBerry") {
var support = blackberry.location.GPSSupported;
if (support) {//refresh the location
blackberry.location.refreshLocation();
latitude = blackberry.location.latitude;
longitude = blackberry.location.longitude;
}
}
document.getElementById("latitude").innerHTML = "Latitude: " + latitude;
document.getElementById("longitude").innerHTML = "Longitude: " + longitude;
}
</script>
</head>
<body onload="updateDate();">
Hello, the current date is:
<div id="divDate"></div>
<br />
<input type="button" value="Show Current Location"
    onclick="locationUpdated();" />
<br />
<div id="latitude" style="width: 200px; height: 20px;"></div>
<div id="longitude" style="width: 200px; height: 20px;"></div>
<div id="lblUpdate">
</body>
</html>

 

 

And, folloing is the Geo-Location JS API code that I have used:

 

<html>
<head>
    <title>Javascript Geo Example</title>
    <script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript" charset="utf-8"></script>
    <script src="C:/Users/Kapil Shardha/Desktop/geo-location-javascript/js/geo.js" type="text/javascript" charset="utf-8"></script>
    <script src="/PluginDemo/geo.js" type="text/javascript" charset="utf-8"></script>
    <script src="" type="text/javascript" charset="utf-8"></script>
</head>    
<body>
    <b>Javascript geo Example</b>
    <script>
        if(geo_position_js.init()){
            geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true});
        }
        else{
            alert("Functionality not available");
        }
 
        function success_callback(p)
        {
            alert('lat='+p.coords.latitude.toFixed(2)+';lon='+p.coords.longitude.toFixed(2));
        }
        
        function error_callback(p)
        {
            alert('error='+p.message);
        }        
    </script>
    </body>
</html>

 

 

Kindly suggest me where am I wrong and what I need to solve this issue. Thanks

 

 

 

 

 

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

Re: Geo-Location JS API not working on BB

In order to get GPS coordinates you need to setup the coordinates of the simulator.  You can do this through the menus at the top of the Simulator screen.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
kks
New Contributor
Posts: 7
Registered: ‎03-12-2010
My Device: 9000
My Carrier: att

Re: Geo-Location JS API not working on BB

Could you kindly elaborate more on what you mean by setting up coordinates for simulator.

 

Thanks

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

Re: Geo-Location JS API not working on BB

[ Edited ]

You can reach the GPS simulation from the "Simulate" menu.  For details on all the configuration that can be done for GPS there are a bunch of topics in the Simulator's online help available from the Help menu.

 

menu.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 2
Registered: ‎06-10-2010
My Device: Not Specified

Re: Geo-Location JS API not working on BB

Hi Tim,do you mean that using Blackberry Simulator,we have to set the location manually in Simulate->GPS Location instead of our application use the GPS function to find the Latitude and Longitude?I am writing Java Application on this and using the Location API and I found that system always return 0 values for Latitude and Longitude. When I set the location manually in Simulate->GPS Location,then the map display as correctly in the Simulator.

Just wonder,in this case will my program run correctly when I move it in real device and nothing need to be set manually?Please advise.Thanks.

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

Re: Geo-Location JS API not working on BB

Your code will work fine on a real device... the issue is that the simulator doesn't have any "live" GPS coordinate data  Smiley Happy

 

So you need to tell the simulator what its GPS coordinates are.  You can even set-up routes that will simulate you moving to different locations that will trigger GPS updates for your application.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 2
Registered: ‎06-10-2010
My Device: Not Specified

Re: Geo-Location JS API not working on BB

i see. This clear my doubts. Thanks for answering my query,really appreciate it.

New Contributor
Posts: 4
Registered: ‎08-31-2010
My Device: BB Bold 9000
My Carrier: Rogers

Re: Geo-Location JS API not working on BB

HI There

I am getting the similar results on my BB Bold 9000.

 

I tried to run this code and it gave me Lat and Lng values as 0.

I even started my GPS service and verified in the GPS options that the Latitude and Longitude are showing actual values instead of 0. I still got the result with the values equal to 0.

 

Can you please help.

Thanks