I am trying to figure out how could I make this work. I am currently working in a cordova / phonegap project.
I have an index.html. There is an image that when clicked, it will go to p_map.html, which contains a Google Map. However, I found out that Geolocation + Google Maps won't work unless you have already opened the Google Maps app on your phone (tested on Samsung Devices). Now I have provided a notification that will tell you to open Google Maps first. However, If they choose the other option, it means that the user already has opened / activated Google Maps in their phone. When the second option is clicked, it will save a status : active on the database, then will proceed to p_map.html. However, when I go back to index.html, the status is again inactive. Can someone please help me? I am new to Web Technologies. Thanks.
index.html
function doSomething(){
navigator.notification.confirm(
'The Map Feature uses Geolocation and Google Maps in order to track your location. Please open Google Maps First.', // message
function whereToGo(button){
if(button == 1){
database.update("mapStatus", {status:"inactive"}, function(row){
row.status = "active";
return row;
});
var results = database.query("mapStatus", {status: "active"});
console.log(results[0].status);
window.open("p_map.html");
}else if(button == 2)
{
navigator.startApp.check("com.google.android.apps.maps", function(message) { /* success */
alert(message + "Google Maps Checked"); // => OK
//start Google Maps if Available
navigator.startApp.start([
"com.google.android.apps.maps", // applucation
], function(message) { /* success */
alert(message + "Start Google Maps"); // => OK
},
function(error) { /* error */
window.open("market://details?id=com.google.android.apps.maps","_system");
});
},
function(error) { /* error */
alert(error);
});
}
alert(button);
}, // callback to invoke with index of button pressed
'Map Setup', // title
["Done, Proceed to Maps", "Go to Google Maps"] // buttonLabels
);
}
</script>
index.js
var database = new localStorageDB("GoogleMap", localStorage);
// Check if the database was just created. Useful for initial database setup
if( database.isNew() ) {
// create the "books" table
database.createTable("mapStatus", ["status"]);
var checkActive = database.query("mapStatus", {status: "active"});
if(checkActive[0].status == "active"){
console.log(results[0].status + "already active");
}else
// insert some data
{ database.insert("mapStatus", {status: "inactive"});
}
// commit the database to localStorage
// all create/drop/insert/update/delete operations should be committed
database.commit();
}
var results = database.query("mapStatus", {status: "inactive"});
console.log(results[0].status);
0 comments:
Post a Comment