2013-10-10 25 views
0

在我的表單中,我有3個隱藏輸入,用於獲取用戶當前的經緯度並將其發送到MySQL數據庫。 我嘗試了一些代碼,但是當我在移動環境中運行它時,它清楚地顯示兩個輸入都沒有填充經度和緯度。JQuery Mobile應用程序上的地理位置

HTML代碼

<div id="clockinPage" data-role="page" data-theme="c"> 
    <div id="wrapper_top_image"> 
     <div id="top_image"></div> 
    </div> 
    <div id="authentic">The information below will be used as Clock-In register.</div> 
    <div data-role="content" > 
     <div id="landmark-1" data-landmark-id="1"> 
      <form id="cname" align="left" action="post" data-ajax="false" > 
       <label for "id">Employee's Name:</label><br/> 
       <select name="id" id="id"> 
       <option value=""></option> 
       </select><br/> 
       <label for "job_id">Job's Name:</label><br/> 
       <select name="job_id" id="job_id"> 
       <option value=""></option> 
       </select><br/> 
       <input type="hidden" name="latitued" id="latitued" value=""><br/> 
       <input type="hidden" name="longitude" id="longitude" value="" > 
       <input type="hidden" name="goo_map_api" id="goo_map_api" value=""> 
       <input type="submit" value="Clock-In" id="enviar_in" data-inline="true">   
      </form> 
     </div> 
    </div 
</div> 

jQuery腳本

$(document).on('pagebeforeshow', '#clockinPage', function() { 

    var Geo={}; 

    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(success, error); 
    } 

    //Get the latitude and the longitude; 
    function success(position) { 
     Geo.lat = position.coords.latitude; 
     Geo.lng = position.coords.longitude; 
     populateHeader(Geo.lat, Geo.lng); 
    } 

    function error(){ 
     console.log("Geocoder failed"); 
    } 

    function populateHeader(lat, lng){ 
     $('#latitued').html(lat); 
     $('#longitude').html(lng); 
     $('#goo_map_api').html("http://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false"); 
    } 

});

當我嘗試從上述表單中發佈信息時,它將返回以下錯誤: 應用程序錯誤 - 出現網絡錯誤。 (文件:/// android_asset /網絡/交ID = 1 & JOB_ID = 2 & latitued = &經度= & goo_map_api =)

這清楚地表明,它獲取輸入選擇ID,輸入選擇JOB_ID但3左,緯度,經度和goo_map_api是空的。 有誰知道發生了什麼? 謝謝。

回答

0

刪除if檢查,只需要:navigator.geolocation.getCurrentPosition(success,error);

+0

我做了,但錯誤仍然存​​在! –

+0

完美@Sheetal。它像一個魅力工作!謝謝。 –

相關問題