2010-10-21 69 views
0

我想要在黑莓手機上的widget應用程序中獲取GPS位置,但API始終返回0,0的經度和緯度。BlackBerry Widget應用程序 - GPS位置總是爲0,0

模擬器:風暴2(9550)/加粗(9700)和OS:5.0/5.0

IDE:Eclipse的

HTML頁面的代碼如下:

var modeCellsite = 0; 
var modeAssisted = 1; 
var modeAutonomous = 2; 

function locationChanged() 
{ 

    alert("Lat " + blackberry.location.latitude + 
      " Lon " + blackberry.location.longitude + 
      " Time " + blackberry.location.timestamp); 
    return true; 
} 

if (window.blackberry && blackberry.location.GPSSupported) 
{ 
    var isUpdated = false; 
    var theCount = 0; 
    alert("Location tracking is supported"); 
    blackberry.location.onLocationUpdate("locationChanged()"); 
    blackberry.location.setAidMode(modeAutonomous); 
    while (theCount++ < 10 && !isUpdated) 
     isUpdated = blackberry.location.refreshLocation(); 
} 
else 
{ 
    document.write("Location tracking is not supported"); 
} 
+0

我有同樣的問題,與略有不同,但spritually simial JS。 – Nilloc 2010-12-07 21:36:54

回答

0

確保你在運行您的小部件之前,在SIM中打開GPS。

For Example in the simulator goto: 
    Simulate -> GPS Location... 
    Under Route Click "add" 
    Choice Random Route Generator 
     Number of Legs 1000 
     Travel Time 600 
     click OK 
    Click Play arrow 
+0

這不會改變我的任何東西......我認爲設置一個位置應該可以發揮作用,並且可以在一條巨大的道路上發送它。 – Nilloc 2010-12-07 21:37:31

+0

@Nilloc我只是指出,你應該確保打開sim的GPS,否則你會得到0,0(默認位置)。使用「巨大路徑」的原因是您的用戶永遠不會靜止不動,因此您應該測試一個路徑而不是單個位置。我會說在Java中需要幾秒鐘才能獲得更新的位置,所以我不認爲在緊密循環中調用refreshlocation()會做很多事情。我相信我看到的例子顯示它在locationChanged()處理程序中被調用一次,然後再次調用。 – eSniff 2010-12-08 00:04:51

相關問題