Getting null value while displaying contacts in iphone phonegap application - iphone

I am working on Phonegap application and trying to get the contacts of the device.
What I have done from this reference is as follows :
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// contacts Methods
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
for (var j=0; j<contacts[i].addresses.length; j++) {
alert("Pref: " + contacts[i].addresses[j].pref + "\n" +
"Type: " + contacts[i].addresses[j].type + "\n" +
"Formatted: " + contacts[i].addresses[j].formatted + "\n" +
"Street Address: " + contacts[i].addresses[j].streetAddress + "\n" +
"Locality: " + contacts[i].addresses[j].locality + "\n" +
"Region: " + contacts[i].addresses[j].region + "\n" +
"Postal Code: " + contacts[i].addresses[j].postalCode + "\n" +
"Country: " + contacts[i].addresses[j].country);
}
}
};
// onError: Failed to get the contacts
function onError(contactError){
alert('onError!');
}
In console while printing the contacts I am getting this error-
[INFO] Error in success callback: Contacts1 = TypeError: 'null' is not an object
There are contacts in my simulator and contact information is not null still I am getting null. Not sure about the reason.
Please help me.
EDIT : same thing is happening when I am playing audio files ..
Any one have idea why this is happening ??

Related

How to replace deprecated jQuery functions?

I am trying to display a map in my UI5 app using a formatter.js where I need to put the address with the map URL together.
In the old world the code should look like the following:
formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
return "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers="
+ jQuery.sap.encodeURL(sStreet + ", " + sZIP + " " + sCity + ", " + sCountry);
},
How should I replace the deprecated function? Where should I add the new code?
If you look at the API documentation for jQuery.sap.encodeURL, you see it states to use the module sap/base/security/encodeURL now.
Usage example from documentation:
sap.ui.require(["sap/base/security/encodeURL"], function(encodeURL) {
var sEncoded = encodeURL("a/b?c=d&e");
console.log(sEncoded); // a%2fb%3fc%3dd%26e
});
Usage in the formatter.js:
sap.ui.define([
"sap/base/security/encodeURL"
], function (encodeURL) {
"use strict";
return {
formatMapUrl: function(sStreet, sZIP, sCity, sCountry) {
var sBaseUrl = "https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=640x640&markers=";
var sEncodedString = encodeURL(sStreet + ", " + sZIP + " " + sCity + ", " + sCountry);
return sBaseUrl + sEncodedString;
}
};
});

Creating a geojson-vt and displaying in Leaflet 0.7

I have a GEOJSON that I am loading up and displaying on a map using Leaflet it is, colour coding them depending on the abundance of the animal in an area and able to display a popup with more information.
What I have been trying to do is turn this into a vectorTile using geojson-vt and display this. This polygon geojson is one of the smaller and takes a long time to load and some others crash the browser.
I have tired to work through the example here http://bl.ocks.org/Sumbera/c67e5551b21c68dc8299 but I cannot understand what is happening.
I am definitely open to other ideas on how to display this data, I am very much a newbie.
If you wish to see what I have so far please look at http://huntingspots.co.nz/gareth/leaflet_layering.html.
Thank you very much for your time.
//Pig Layer
var pigLayer = new L.LayerGroup();
$.getJSON("feralpig.geojson",function(hoodData){
L.geoJson( hoodData, {
style: function(feature){
var fillColour,
abundance = feature.properties.Abundance;
if (abundance == "H") fillColour = "#194866";
else if ( abundance == "M" ) fillColour = "#2c7eb2";
else if ( abundance == "L" ) fillColour = "#40b5ff";
else fillColour = "#f7f7f7"; // no data
return { color: "#999", weight: 1, fillColor: fillColour, fillOpacity: .4 };
},
onEachFeature: function( feature, layer ){
layer.bindPopup( "<strong>" + "Species: " + "</strong>" + feature.properties.Scientific
+ "<br/>" + "<strong>" + "Common Name: " + "</strong>" + feature.properties.CommonName
+ "<br/>" + "<strong>" + "Abundance: " + "</strong>" + feature.properties.Abundance
+ "<br/>" + "<strong>" + "Data collection method: " + "</strong>" + feature.properties.AbundRelia
+ "<br/>" + "<strong>" + "Notes: " + "</strong>" + feature.properties.AbundNotes);
}
}).addTo(pigLayer);
});

NodeRed Function Node Crashes - [red] Uncaught Exception:

I am having a hard time understanding why my Node-Red Flow keeps crashing with an [RED] Uncaught Exception. It almost seems like the function node is crashing and my code inside of the function node never has a chance to catch it.
I have a very simple Node-Red flow that executes a IBMDB node.js library to insert data into my database. In order to use the IBMDB library, I had to add the package to the list of packages in my packages.json file. I also had to setup a global context variable inside the Bluemix-setings.js file. I named this global context variable IBMDB, which is the equivalent to the require statement. Once that was done, I am able to make use of the library inside a function node.
** Here is the Node.js IBMDB library, I am using.
https://github.com/ibmdb/node-ibm_db
** Here is the Flow
** Here is the code inside the function.
try {
context.global.ibmdb.open("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;", function (err,conn) {
conn.beginTransaction(function (err) {
if (err) {
//could not begin a transaction for some reason.
console.log(err);
return conn.closeSync();
}
for (i = 0; i < msg.payload.Readings.length; i++)
{
var result = conn.querySync("INSERT INTO db2.table (" +
"I_ID," +
"D_ID," +
"field1," +
"field2," +
"field3," +
"field4," +
"field5," +
"field6," +
"field7," +
"field8," +
"field9," +
"field10)" +
"values (" +
"1A," +
"'"+ msg.payload.field1 + "',"+
"'" + JSON.stringify(msg.payload.Readings[i].field2) + "'," +
msg.payload.Readings[i].field3 + ","+
msg.payload.Readings[i].field4 + ","+
msg.payload.Readings[i].field5 + ","+
msg.payload.Readings[i].field6 + ","+
msg.payload.Readings[i].field7 + ","+
msg.payload.Readings[i].field8 + ","+
msg.payload.Readings[i].field9 + ","+
msg.payload.Readings[i].field10 + ","+
"'2016-05-31 22:28:51.000000'" +
");");
}
conn.commitTransaction(function (err) {
if (err) {
//error during commit
console.log("****ERROR: " + err);
node.error("**** ERROR: ", err);
//return conn.closeSync();
}
//Close the connection
conn.closeSync();
});
});
});
} catch (e) {
node.error("**** ERROR: ", err);
}
When I run this with a valid SQL statement and all the data types are correctly sent, I get no errors. Everything works!!
*** The issue: When I did some testing to force a SQL error, the Node-Red instance crashes. I forced the error by sending a valid SQL statement, but the data elements in one of the fields is a non-numeric value where the table definition is expecting numeric only. I see in the error logs (console out) two lines..
The error SQL error message displayed is exactly what I was expecting to catch in my application. Instead the application just crashes.
[red] Uncaught Exception: Error: [IBM][CLI Driver][DB2/LINUXX8664]
SQL0103N The numeric literal "1A" is not valid. SQLSTATE=42604
Any insight on what is really happening would be greatly appreciated. I am wondering if I put this code inside a custom built node would I be able to catch the error. Could this be a limitation of using the function node as a wrapper to my code. ????
*
Try wrapping the conn.querySync call in it's own try/catch block. The current block is out of scope because the call happens in another function (the one passed into beginTransaction).
e.g.
try {
context.global.ibmdb.open("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;", function (err,conn) {
conn.beginTransaction(function (err) {
if (err) {
//could not begin a transaction for some reason.
console.log(err);
return conn.closeSync();
}
for (i = 0; i < msg.payload.Readings.length; i++)
{
try {
var result = conn.querySync("INSERT INTO db2.table (" +
"I_ID," +
"D_ID," +
"field1," +
"field2," +
"field3," +
"field4," +
"field5," +
"field6," +
"field7," +
"field8," +
"field9," +
"field10)" +
"values (" +
"1A," +
"'"+ msg.payload.field1 + "',"+
"'" + JSON.stringify(msg.payload.Readings[i].field2) + "'," +
msg.payload.Readings[i].field3 + ","+
msg.payload.Readings[i].field4 + ","+
msg.payload.Readings[i].field5 + ","+
msg.payload.Readings[i].field6 + ","+
msg.payload.Readings[i].field7 + ","+
msg.payload.Readings[i].field8 + ","+
msg.payload.Readings[i].field9 + ","+
msg.payload.Readings[i].field10 + ","+
"'2016-05-31 22:28:51.000000'" +
");");
} catch (excp) {
//do stuff
}
}
conn.commitTransaction(function (err) {
if (err) {
//error during commit
console.log("****ERROR: " + err);
node.error("**** ERROR: ", err);
//return conn.closeSync();
}
//Close the connection
conn.closeSync();
});
});
});
} catch (e) {
node.error("**** ERROR: ", e);
}

ngCordova watchPosition is not working in ionic framework

I 'm working on an app in ionic framework in which I want to get location of device.
It works fine for getCurrentPosition
But when I try to use watchPosition, so that I can get new position whenever there is a change in location of device. it does nothing.
I 'm not sure what I 'm missing
my controllers.js code
.controller('LocCtrl', function($scope,$cordovaGeolocation) {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
}, function(err) {
alert(err);
});
var watchOptions = {
timeout : 3000,
enableHighAccuracy: false // may cause errors if true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.promise.then(
null,
function(err) {
alert("error:"+err);
},
function(position) {
var lat = position.coords.latitude
var long = position.coords.longitude
alert("Lat in Watch:"+lat);
});
$cordovaGeolocation.clearWatch(watch.watchId);
})
I used some alert messages to see whats happening,
In current setuation, it gives two alert messages giving getCurrentPosition, but noting happens on changing device Location.

Workflow for Google Apps script approving correct row via email

I am creating a workflow process with Google Apps script. I have looked at this video for most of the layout.
I built a form in Google Apps script that takes input data from a user. The data is then submitted into rows with e.parameter values. That data is then emailed to an approver. The approver has an approve button that they press to change the "Status" column to approved.
Issue:
I cant get the data to approve the correct row. I am passing a row parameter that is supposed to correspond to the correct row but it isnt working.
Here is my code that submits data to the spreadsheet and once the data has been approved via email. The DoPost function runs and approves the row. Can someone Please help! I've been trying to find solutions all day.
function sendEmail_(e) {
var sheet = SpreadsheetApp.openById("0AuCblud0Ss7BdHA1bXZjYXA0Y0IyekhUQm5vWG02MVE").getActiveSheet();
var range = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 13);
range.setValues([
[e.parameter.LastName, e.parameter.FirstName, e.parameter.DivisionName, e.parameter.EffectiveDate,
e.parameter.Network, e.parameter.EmployeeNewPosition, e.parameter.DivisionFolder, e.parameter.SpecificIndividual,
e.parameter.Email, e.parameter.username, e.parameter.who, e.parameter.Banner, "Unapproved"]
]);
var row = sheet.getLastRow() + 1;
//"https://script.google.com/a/macros/wichitafallstx.gov/s/AKfycbwOgTTGqNsVwnqs-xfqa7TEJWGc_lJZdoyoEoixngKdDemVQuo/exec
var body = '<form action= <form action = " https://sites.google.com/a/macros/wichitafallstx.gov/s/AKfycbxAOGO6q9ofauf34xlDA9sLG8sUXeZsuvQkDKATOQ/exec" method ="post">' +
"<b>Last Name:</b>" + e.parameter.LastName + '<br><br>' +
"<b>First Name:</b>" + e.parameter.FirstName + '<br><br>' +
"<b>Division Name:</b>" + e.parameter.DivisionName + '<br><br>' +
"<b>Effective Date:</b>" + e.parameter.EffectiveDate + '<br><br>' +
"<b>Network:</b>" + e.parameter.Network + '<br><br>' +
"<b>Employee New Position:</b>" + e.parameter.EmployeeNewPosition + '<br><br>' +
"<b>Division Folder:</b>" + e.parameter.DivisionFolder + '<br><br>' +
"<b>Specific Individual:</b>" + e.parameter.SpecificIndividual + '<br><br>' +
"<b>Email:</b>" + e.parameter.Email + '<br><br>' +
"<b>Username:</b>" + e.parameter.username + '<br><br>' +
"<b>who:</b>" + e.parameter.who + '<br><br>' +
"<b>Banner:</b>" + e.parameter.Banner +
'<br />' +
'<br />' +
'<input type="hidden" name="row" value=" ' + row + ' "/>' +
'<input type="submit" value="Approve" onclick="approve()" />' +
'</form>';
var owners = SitesApp.getSite("wichitafallstx.gov", "information-systems").getOwners();
var mail = MailApp.sendEmail(owners.join(","), "test", '', {
htmlBody: body
});
}
//handles the payload that is posted back to appscript..from the form that is passed from the form created in send email.
function doPost(e) {
var r = e.parameter["row"];
var sheet = SpreadsheetApp.openById("0AuCblud0Ss7BdHA1bXZjYXA0Y0IyekhUQm5vWG02MVE").getActiveSheet();
var values = sheet.getRange(r, 1, 1, 13).getValues();
sheet.getRange(r, 13).setValue("Approved");
}
I am passing a row parameter that is supposed to correspond to the correct row but it isnt working.
It appears that you are passing the row below the one intended.
var range = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 13);
range.setValues([
[e.parameter.LastName, e.parameter.FirstName, e.parameter.DivisionName, e.parameter.EffectiveDate,
e.parameter.Network, e.parameter.EmployeeNewPosition, e.parameter.DivisionFolder, e.parameter.SpecificIndividual,
e.parameter.Email, e.parameter.username, e.parameter.who, e.parameter.Banner, "Unapproved"]
]);
// In assignment below 'new' lastRow is the row you just filled
// in with above and should not include + 1
var row = sheet.getLastRow() // no + 1;