06-15-2011 01:37 AM
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.
06-15-2011 02:14 PM
Have you checked out the followig tutorial?
06-16-2011 12:28 AM
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(geolocati
}
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...
06-16-2011 09:16 AM
Which version of the BB6 OS is on the simulator? There are some simulators out there where GPS emulation is just plain broken.
06-17-2011 01:07 AM
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.