PhoneGap(Andriod)如何获得地理位置及拍摄照片
1.首先我们按照getting start的文档建立项目:
2. 调用js
得到坐标:
[javascript]
var getLocation = function() {
var suc = function(p) {
alert(p.coords.latitude + " " + p.coords.longitude);
};
var locFail = function(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
};
navigator.geolocation.getCurrentPosition(suc,locFail);
};
如果返回error可能是手机游览器中的地理功能没打开(http://stackoverflow.com/questions/5407973/navigator-geolocation-getcurrentposition-throws-the-last-location-provider-was)
拍摄照片:
[javascript]
function dump_pic(data) {
var viewport = document.getElementById('viewport');
console.log(data);
//alert(data);
viewport.style.display = "";
viewport.style.position = "absolute";
viewport.style.top = "10px";
viewport.style.left = "10px";
document.getElementById("test_img").src = data;
}
function fail(msg) {
alert(msg);
}
function show_pic() {
navigator.camera.getPicture(dump_pic, fail, {
quality : 50
});
}
作者:xiaoguang44
补充:移动开发 , Android ,