doujie7346 2019-02-25 11:49
浏览 138

Cordova:将图像和位置上传到数据库,然后加载最近的图像

I'm Trying to build an app with Cordova. With the app you should take pictures, these pictures needs to be uploaded to a database together with the location where the picture is taken. The app on default shows a x number of the most nearest taken pictures to your live location. Beneath here i post the javascript code i have right now, most of the code is from Cordova self. Is it better to modify this code or start over?

I can now access the camera and take a picture, but how do i upload this picture together with the location to a database?

And how can load the nearest pictures from the database?

var Latitude = undefined;
var Longitude = undefined;

window.onload = function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady(){
    navigator.notification.alert("ready");
    document.getElementById("camera").addEventListener 
        ("click", cameraTakePicture); 
}

function cameraTakePicture() { 
    navigator.camera.getPicture(onSuccess, onFail, {  
       quality: 50, 
       destinationType: Camera.DestinationType.DATA_URL 
    });  

  function onSuccess(imageData, imageURI) { 
     var image = document.getElementById('myImage'); 
     image.src = "data:image/jpeg;base64," + imageData;
     getLocation();
     navigator.notification.alert(image.src);
  }  

  function onFail(message) { 
     alert('Failed because: ' + message); 
  } 
 }

 function getLocation() {
    navigator.notification.alert("start locatie");
    navigator.geolocation.getCurrentPosition(onPicturesSuccess, onPicturesError, { enableHighAccuracy: true });
 }

var onPicturesSuccess = function (position) {

  Latitude = position.coords.latitude;
  Longitude = position.coords.longitude;

  getPictures(Latitude, Longitude);
}

function getPictures(latitude, longitude) {
  //Load pictures which are the nearest
}

var onPicturesWatchSuccess = function (position) {

   var updatedLatitude = position.coords.latitude;
   var updatedLongitude = position.coords.longitude;

   if (updatedLatitude != Latitude && updatedLongitude != Longitude) {

     Latitude = updatedLatitude;
     Longitude = updatedLongitude;

     getPictures(updatedLatitude, updatedLongitude);
   }
}

// Error callback

function onPicturesError(error) {

   console.log('code: ' + error.code + '
' +
       'message: ' + error.message + '
');
}

// Watch your changing position

function watchPicturePosition() {

   return navigator.geolocation.watchPosition
   (onPicturesWatchSuccess, onPicturesError, { enableHighAccuracy: true });
}
  • 写回答

2条回答 默认 最新

  • 普通网友 2019-02-25 13:52
    关注

    You can use Cordova File Transfer Plugin to upload your photos to your backend service (DB). In FT Plugin you can add some additional headers, or properties e.g. LAT and LON properties.

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧