Reputation: 1059
I am developing a blackberry application using html5 code.I need to find my current location and have to show that in Google map.I am running this in BB9780. It is running in simulator but it gives a wrong location(US location). But it is not running in device.
I suspect the below line is not executing.
navigator.geolocation.getCurrentPosition(onSuccess, onError);
I am giving my code here.Please suggest me where I went wrong
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=device-width,height=device- height,initial-scale=1.0,user-scalable=no">
<script src="json2.js" type="text/javascript"></script>
<script src="cordova-1.7.0.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
alert("onDeviceReady");
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
function onSuccess(position) {
alert("onSuccess");
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Accuracy: ' + position.coords.accuracy + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Heading: ' + position.coords.heading + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />';
}
// onError Callback receives a PositionError object
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
<title>Notification Sample</title>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>
Upvotes: 0
Views: 1816
Reputation: 5745
please try to add timeout:10000
to see the error log..
it is probably a timeout issue on your specific device
try:
gl.getCurrentPosition(onSuccess, onError,{timeout:10000});
instead
related issue i found on github: https://github.com/apache/cordova-plugin-geolocation/issues/119#issuecomment-463897045
and here: phonegap geolocation always fail on timeout
Upvotes: 0
Reputation: 2192
i get solution by restarting my device like i am not restarting my device from 1 month
So restart your device may you get solution
Upvotes: 0
Reputation: 49
I dont think its the line you suspect, what is the error message your getting? Its probably the simulator as your code looks correct, though I'm only reading error.message and error.code. This my version of onDeviceReady
function onDeviceReady() {
try {
if(typeof(navigator.geolocation)!='undefined') gl = navigator.geolocation;
else gl=google.gears.factory.create('beta.geolocation');
}catch(e){}
if (gl) {
gl.getCurrentPosition(onSuccess, onError);
alert("Device Ready");
} else {
alert('not supported');
}
}
Upvotes: 0