2012-05-31 3 views
0

Я разрабатываю приложение Blackberry с использованием кода html5. Мне нужно найти свое текущее местоположение и показать, что в карте Google. Я запускаю это в BB9780. Он работает в симуляторе, но он дает неправильное местоположение (местоположение в США). Но он не работает в устройстве.navigator.geolocation.getCurrentPosition (onSuccess, onError); не работает

Я подозреваю, что нижняя строка не выполняется.

navigator.geolocation.getCurrentPosition (onSuccess, onError);

Я даю мой код here.Please предложить мне, где я не заладилось

<!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> 

ответ

0

Я не думаю, что его линия вы подозреваете, что сообщение об ошибке Ваше получение? Вероятно, это симулятор, так как ваш код выглядит правильно, хотя я только читаю error.message и error.code. Это моя версия 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'); 
    } 
} 
0

я получить решение путем перезапуска моего устройства как я не перезапускаюсь мое устройство от 1 месяца

Так перезагрузить устройство может вы получите решение

Смежные вопросы