Phonegap构建Geolocation无法正常工作

时间:2015-10-27 07:06:29

标签: javascript cordova geolocation phonegap-plugins

js:我使用简单的警报来显示位置,并使用phonegap build进行编译。显示设备就绪警报!但没有任何其他警报!

alter procedure AutoUpdate_EmpSal
as
begin
DECLARE @cmd AS NVARCHAR(max)
CREATE TABLE #result 
        (           
           SalaryId          int,
           EmpId             INT,           
           TakenSalary       float,
           AvailSalary       float
        )       
declare @salaryId   int
declare @empId  int
declare @takenSalary float
declare @availSalary float

SET @cmd ='select * from Employee_SalaryDetails where SalaryId in( SELECT max(SalaryId) FROM Employee_SalaryDetails group by EmpId )'
Insert into #result 
         EXEC(@cmd)

declare result_cursor cursor for 
    select SalaryId,EmpId,TakenSalary,AvailSalary
    from  #result

OPEN result_cursor
FETCH NEXT FROM result_cursor INTO @salaryId,@empId,@takenSalary,@availSalary

WHILE @@FETCH_STATUS = 0                                          
BEGIN   
    update Employee_SalaryDetails 
    set Employee_SalaryDetails.AvailSalary=(@availSalary+Employee.Salary)
    from Employee_SalaryDetails,Employee
    where Employee_SalaryDetails.SalaryId=@salaryId 
    and Employee_SalaryDetails.EmpId=Employee.EmpId
FETCH NEXT FROM result_cursor INTO @salaryId,@empId,@takenSalary,@availSalary
end
select * from #result
end

html:html页面如下:

document.addEventListener("deviceready", getDeviceLocation , false); 

    function  getDeviceLocation () {
         alert('device ready');      
         navigator.geolocation.getCurrentPosition(showPosition, showError, { enableHighAccuracy: true } );
    }

     function showPosition(position) {
        alert('show postion called');
          alert("Latitude: " + position.coords.latitude + 
                    "Longitude: " + position.coords.longitude);    
  }

  function showError(error) {
        alert('show error called');
        alert("Errorcode: "    + error.code    + 
                 "Errormessage: "+ error.message );
    }

1 个答案:

答案 0 :(得分:3)

此代码适用于我。希望能帮到你。

newMapForGuest: function()
{
    // setting here default latitude and longitude in case geolocation does not work.
    var defaultLatLng = new google.maps.LatLng(1.290, 103.851);
    if ( navigator.geolocation ) 
    {
        function success(pos) // function will call on success
        {
            alert('Latitude: '+ pos.coords.latitude +' Longitude: '+pos.coords.longitude);
        }

        function fail(error) // function will call on fail
        {
            alert('error message: ' +error);
        }
        // intializing geolocation to get current position
        navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 10000});
    } 
    else 
    {
        // in case geolocation does not work then call code mentioned here.
    }
},