Book Image

PhoneGap By Example

Book Image

PhoneGap By Example

Overview of this book

Table of Contents (17 chapters)
PhoneGap By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Saving data in local storage


We have captured a picture, assigned a caption, moved the picture to the persistent store, and detected the picture's location. Now, we need to save this information into the application's database:

savePhoto: function(imageURI, title) {
    var self = this;
    self.copyPhotoToPersistentStore(imageURI, function(persistentImageURI) {
        self.getCurrentPosition(function(latitude, longitude) {
            var picture = Ext.create('Travelly.model.Picture', {
                url: persistentImageURI,
                title: title,
                lat: latitude,
                lon: longitude
            });
            var pictureStore = Ext.getStore('Pictures');
            pictureStore.add(picture);
            pictureStore.sync();

            var map = self.getMapPlaces().getMap();
            Travelly.app.getController('Places').addMarker(picture, map);
        });
    })
}

Here, we created the Picture model with the persistent image URI, title, and coordinates...