我想使用 -
中列出的APIhttp://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!