相机中的离子保存图像,包含一些信息并从图库中获取

时间:2016-09-05 05:57:51

标签: javascript ionic-framework

我正在研究Ionic移动应用程序我的任务是,如果一个人点击相机中的图像,图片将以他的纬度和经度保存,他可以选择图像并将其上传,以便保存的图片与其坐标。

我面临的问题是,当我从相机拍摄时,它会使用自动生成的名称进行保存。我可以在本地存储中保存该名称的纬度和经度,但是当我从图库中获取该图像时,它会出现一个不同的名称和路径,因此我无法获取该图像的信息。

我的捕捉图片代码:

 $scope.takePicture = function(){
        //alert("Hello World");
        var options={
            quality : 75,
            destinationType : Camera.DestinationType.FILE_URI,
            sourceType : Camera.PictureSourceType.CAMERA,
            allowEdit : false,
            encodingType: Camera.EncodingType.JPEG,
            targetWidth: 300,
            targetHeight: 300,
            popoverOptions: CameraPopoverOptions,
            saveToPhotoAlbum: true,
            correctOrientation: true
        };

        $cordovaCamera.getPicture(options).then(function (imageData) {
            $scope.showImage = true;
            $scope.showFormPickup = false;
            $scope.showSeatAvaiable = false;
            $scope.showRequestWating = false;
            $rootScope.aloTaxiHeaderBarClass = 'overlay';

            //Store File URL in variable
            $scope.fileUrL = imageData;
          $scope.imgURI = imageData;
          //Store File URL in variable
          //alert($scope.imgURI);

          var filename= $scope.fileUrL.split("/").pop();
          //alert(filename);
          filename = filename.substr(0,filename.lastIndexOf('.'));
          //alert(filename);
          $scope.fileNameGalery = filename;
          //alert($scope.fileNameGalery);

          //alert('File Name:' + filename);

          $scope.getLocation();

          //alert('Latitude:' + $scope.latitude + 'Longitude:' + $scope.longitude);

        },function(err){
            console.log('Error While Taking Pictures:' + err);
        });
    }
  $scope.getLocation=function () {
    //alert("in geo location")
    try {
      var platform = $cordovaDevice.getManufacturer();
      //alert('Device:' + device.isVirtual + 'Platform:' + platform);
      //alert('Platform:' + platform);
      if (platform === 'Genymotion' || platform === 'unknown' || platform == "undefined") {
        //alert('Platform is GennyMotion');
        $scope.latitude = '24.830814';
        $scope.longitude = '67.072883';
      }
      else {
        $scope.getLocationFromGPS();
      }
    }
    catch(err){
      //alert(err);
    }
  }
  $scope.getLocationFromGPS=function () {
    //alert("getLocationFromGPS");
    var posOptions = {
      enableHighAccuracy: true,
      timeout: 20000,
      maximumAge: 0
    };
    $cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
      //var lat=position.coords.latitude;
      //var long=position.coords.longitude;

      $scope.latitude=position.coords.latitude;
      $scope.longitude=position.coords.longitude;
      if($scope.fileNameGalery != "undefined") {
        if (typeof(Storage) != "undefined") {
          //alert("local Storage");
          var myObj = {name: $scope.fileNameGalery, latitude: $scope.latitude, longitude: $scope.longitude};
          //alert(angular.toJson(myObj));
          try {
            localStorage.setItem($scope.fileNameGalery, JSON.stringify(myObj));
          }
          catch(err){
            //alert(err);
          }
        } else {
          //alert("Sorry Browser does not support Local Storage Feature");
        }
      }
      //alert('Latitude:' + $scope.latitude + 'Longitude:' + $scope.longitude);

    },function (err) {
      console.log('Error:' + err);
    });
  }
从图库代码中获取图片的

是:

   $scope.choosePhoto = function () {
    var options = {
      quality: 75,
      destinationType: Camera.DestinationType.FILE_URI,
      sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
      allowEdit: false,
      encodingType: Camera.EncodingType.JPEG,
      targetWidth: 300,
      targetHeight: 300,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function (imageData) {
      $scope.showImage = true;
      $scope.showFormPickup = false;
      $scope.showSeatAvaiable = false;
      $scope.showRequestWating = false;
      $rootScope.aloTaxiHeaderBarClass = 'overlay';
      $scope.imgURI = imageData;
      //Store File URL in variable
      $scope.fileUrL = imageData;

      //alert("Image URL:" + $scope.imgURI);

      var filename= $scope.fileUrL.split("?").pop();
      //alert(filename);
      filename = filename.substr(0,filename.length);
      //alert(filename);
      try {
        var item = angular.fromJson(localStorage.getItem(filename));
        //alert(item);
        $scope.latitude = item["latitude"];
        $scope.longitude = item["longitude"];

        //alert($scope.latitude);
        //alert($scope.longitude);
      }
      catch (err)
      {
        //alert(err);
      }
      //alert('File Name:' + filename);

     // $scope.getLocation();

      //alert('Latitude:' + $scope.latitude + 'Longitude:' + $scope.longitude);

      //if(typeof(Storage) != "undefined") {

        //var myObj={name:filename,latitude:$scope.latitude,longitude:$scope.longitude};
        //localStorage.setItem(filename,JSON.stringify(myObj));
      //} else {
       // alert("Sorry Browser does not support Local Storage Feature");
     // }
    }, function (err) {
      console.log('Error While getting pictures from gallery' + err);
    });
  }

0 个答案:

没有答案