I'm developing an app that consists of a map and a camera. At the moment, I want to add the possibility of the user taking a photo with the camera and mark the map where this photo was taken, but I have a hard time storing the photo in the object that stores the information of the places saved on the map. I'll put some code snippets that I consider to be key:
addLocation.html snippet:
<label class="item item-input">
<span class="input-label">Name</span>
<input type="text" ng-model="newLocation.name" placeholder="What's Here?" ng-minlength="1" ng-maxlength="100" required>
</label>
<label class="item item-input">
<span class="input-label">Picture</span>
<button class="button icon-left ion-image button-calm" ng-click="selectPhoto()">Select an image</button>
</label>
<div>
<img id="photo" height="256" width="256">
</div>
<div class="item tabs tabs-secondary tabs-icon-left">
<a class="tab-item" href="#">
LAT : {{newLocation.lat | truncate:15}}
</a>
<a class="tab-item" href="#">
LNG : {{newLocation.lng | truncate:15}}
</a>
app.js excerpt: selectPhoto () function:
$scope.selectPhoto = function() {
Camera.getPicture({
quality: 75,
destinationType: 1,
sourceType: 0,
correctOrientation: true
}).then(function(imageURI) {
var image = document.getElementById('photo');
image.src = imageURI;
image.style.margin = "0 auto";
image.style.display= "block";
$scope.newLocation.photo = new Image();
$scope.newLocation.photo.src = imageURI;
},function(err) {
console.err(err);
});
}
section of mapController.js:
$scope.saveLocation = function() {
LocationsService.savedLocations.push($scope.newLocation);
$scope.modal.hide();
$scope.goTo(LocationsService.savedLocations.length - 1);
};
var location = LocationsService.savedLocations[locationKey];
$scope.map.markers[locationKey] = {
lat:location.lat,
lng:location.lng,
message: location.name + location.photo,
focus: true,
draggable: false
};
In the selectPhoto () function, after selecting the photo of the album, the source of the variable 'image' is being changed and in html the selected image appears. However, I can not save the same image in newLocation.photo, which gets undefined even after selecting the photo. I believe the error is in
$scope.newLocation.photo = new Image();
$scope.newLocation.photo.src = imageURI;
from app.js
I think it's not something complex to solve and that I'm probably doing some simple nonsense, since I'm a beginner in JS, html, etc. But I really do hope for help. Thanks