8. JavaScript控制设备密度
Android浏览器和WebView支持查询当前设备密度的DOM特性 (window.devicePixelRatio),该值指定用于当前设备按比例 缩放的系数。例如,值为“1.0”,则说明设备是中等密度,并且 默认页面丌迚行缩放;如果该值是“1.5”,那么,设备是高密度 设备,并且默认页面调整1.5x(倍);如果该值是“0.75”,那 么,设备是低密度设备,并且默认页面调整0.75x(倍)。
如何使用JavaScript查询设备密度: if (window.devicePixelRatio== 1.5) { alert("This is a high-density screen"); } else if (window.devicePixelRation== 0.75) { alert("This is a low-density screen"); }
20. HTML5地理定位API
position对象所包含的数据:
Property
Type
Notes
coords.latitude(纬度)
double
Decimal degrees
coords.longitude(经度)
double
Decimal degrees
coords.altitude(海拔)
double or null
Meters
coords.accuracy(精确度)
double
Meters
coords.altitudeAccuracy
double or null
Meters
coords.heading(朝向)
double or null
degrees clockwise from the north
coords.speed
double or null
Meters/second
timestamp
DOMTimeStamp
Like a Date() object
Error代码:
TIMEOUT:表示获取信息超时。
PERMISSION_DENIED:表示用户选择了拒绝了位置服务。
POSITION_UNAVAILABLE:表示位置丌可知。
Position选项:
Property
Type
Default
Notes
enableHighAccuracy
boolean
false
true might be slower
timeout
long
(no default)
In milliseconds
maximumAge
long
0
In milliseconds