如何使用移动应用中的HTML5 - Vehicle Information API访问车速数据?

时间:2015-01-22 09:03:47

标签: javascript html5 api w3c

我想使用 -

中列出的API

http://www.w3.org/2014/automotive/data_spec.html

http://www.w3.org/2014/automotive/vehicle_spec.html

那么,我该如何开始?它们与所有型号和汽车制造商兼容吗?

如何使用这些API开始开发应用?

我试过这个样本:

<!DOCTYPE html>  
<html>
<body>

<p>Click the button to get your coordinates.</p>

<button onclick="getSpeedOfVehicle()">Try It</button>

 <p id="demo"></p>

<script>

var vehicle = navigator.vehicle;

if(navigator.vehicle)
 {
     alert("yes")
 }
 else
{
    alert("no")
}
 function getSpeedOfVehicle(){

   vehicle.vehicleSpeed.get().then(function(vehicleSpeed) {
      console.log("vehicle speed: " + vehicleSpeed.speed);
   },
   function(error) {
     console.log("There was an error");
   });

  var vehicleSpeedSub =        vehicle.vehicleSpeed.subscribe(function(vehicleSpeed) {
       console.log("vehicle speed changed to: " + vehicleSpeed.speed);
      vehicle.vehicleSpeed.unsubscribe(vehicleSpeedSub);
  });


   }
 }
  </script>

 </body>
 </html>

  And it displays / alerts - "no", which indicates its not yet implemented by the browser. So how do we proceed?  

Thanks in advance!

0 个答案:

没有答案