Hello,
I would like to get help on a few things,
- Where exactly am I supposed to write cordova plugin code? I mean should I do this code in my-
app.js
or the phonegapindex.js
? This is because I have a page that will require a user’s location on load, If the user denies permission, it should reload the page triggering a permission request again…
I tried the geolocation plugin in my heloworld phonegap project and I got these…
I am now not sure where it all fits in framework7… For example,
in phonegap
` var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// ‘load’, ‘deviceready’, ‘offline’, and ‘online’.
bindEvents: function() {
document.addEventListener(‘deviceready’, this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of ‘this’ is the event. In order to call the ‘receivedEvent’
// function, we must explicitly call ‘app.receivedEvent(…);’
onDeviceReady: function() {
var WatchID = navigator.geolocation.getCurrentPosition(onSuccess,OnError,{ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true });
}
};
var onSuccess = function(position) {
// Storing the lat and long values from navigator.gelocation object to variables
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var ExtraInfo = 'Longitude = '+longitude+' Latitude ='+latitude;
alert(ExtraInfo);
}
var OnError = function(error) {
alert('code: ’ + error.code + ‘\n’ +
'message: ’ + error.message + ‘\n’);
}`
How best do I do this kind of implementation on a page say:
in my-app.js
$$(document).on('page:init', '.page[data-name="my-location-page"]', function (e) { //check -if (deviceisready), **//then trigger the 'allowLocation' permission in a phone** // -if(userAllows) **//doSomething();** else **//alert user,reload page until user accepts** //else, DeviceIsNotReady, Alert user... })
Main question: Where does this code go? (index.js / myapp.js)
How do I check if deviceisready
in all instances it is important in an if---else
situation? I need to know how cordova works clearly with F7… From there, we are good. I am sorry, I am teaching myself all these fro the documentation… I am new to hybrid app dev but I must get the job done… I am learning on work… I feel confortable writing all my code in one file my-app.js
.
Once I now these, then it will be easy for me to check if there is connection, and several other things that require cordova… Thanks in advance, Thanks Vlad for this awesome framework!