2013-10-31 38 views
1

我想捕獲Web用戶的地理位置數據並將其存儲在帶有服務器端JavaScript的Notes文檔中。在XPages中捕獲地理位置

因爲我知道XPages沒有檢測地理位置的控件,CGI變量也沒有幫助。

我該怎麼做?

+0

\t \t ! \t \t \t <![CDATA [$(文件)。就緒( \t $獲得(「HTTP ('#ip')。html('IP:'+ response.ip); $('#address')。html('Location:'+ ('#details')。html(JSON.stringify(response,null,4)); x $(「#{id:inputText1}」)。 val(response.city) },'jsonp') ); ]]> \t \t \t

+0

但加載頁面時,還沒有準備好... –

回答

0

以下是我用來查找頁面加載時的地理座標的腳本塊的相關部分。與我已經測試過的WebKit瀏覽器一起使用,但不適用於IE。

<xp:scriptBlock> 
     <xp:this.value><![CDATA[ 
var geo_location = { 
    latitude : 0, 
    longitude : 0, 
    emsg : "", 

    showLocation : function(position) { 
     geo_location.latitude = position.coords.latitude; 
     geo_location.longitude = position.coords.longitude; 

     var prOptions = {"latitude" : geo_location.latitude, 
         "longitude" : geo_location.longitude, 
         "msg" : geo_location.emsg}; 

     XSP.partialRefreshGet("#{id:geoLocationPanel}", 
     { 
      params : prOptions, 
      onError : function() { 
       alert("geoLocationPanel partialRefresh Error"); 
      } 
     }); 
    } 
}; 

XSP.addOnLoad(function(){ 
    setTimeout(function(){ 
     // function to get the current geo location 
     try { 
      navigator.geolocation.getCurrentPosition(geo_location.showLocation); 
     } catch (e) { 
      geo_location.emsg = e.toString(); 
      alert("navigator.geolocation Error\n" + geo_location.emsg); 
      geo_location.showLocation({ 
       coords : { 
        latitude : 0, 
        longitude : 0 
       } 
      }) 
     } 
    }, 200); 
} 
)]]></xp:this.value> 
</xp:scriptBlock>