I need to tabulate informations from Google JSON file, that is an output of a query to google in order to obtain transit time with and without traffic recorded in a table
I tried to use the ajax loading method as follows (with the correct link instead of "http://www.getmydata.com/now"
var table = new Tabulator("#example-table", {
ajaxURL:"http://www.getmydata.com/now", //ajax URL
});
I retrieve an error from the tabulator.
Google Json response has this format:
{
"destination_addresses" : [ "Los Cuartos, Naucalpan de Juárez, Méx., Messico" ],
"origin_addresses" : [ "Città del Messico, Distretto Federale, Messico" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "17,6 km",
"value" : 17553
},
"duration" : {
"text" : "38 min",
"value" : 2273
},
"duration_in_traffic" : {
"text" : "31 min",
"value" : 1878
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
Any hint how to solve??
Related
How do you add a service charge to an order using the Square API? Here is the documentation but they don't give an example.
https://developer.squareup.com/reference/square/orders-api/create-order
This is what I tried to add to my request but I'm not seeing this charge in my order. My line items and sales tax works but I can't get the service charges added to an order.
{
"idempotencyKey" : "ABC",
"order" : {
"locationId" : "123",
"lineItems" : [
{
"name" : "My Item",
"quantity" : "1",
"basePriceMoney" : {
"amount" : 2499,
"currency" : "USD"
}
}
],
"taxes" : [
{
"uid" : "state-sales-tax",
"name" : "State Sales Tax",
"percentage" : "7.30",
"scope" : "ORDER"
}
],
"service_charges" : [
{
"uid" : "delivery-fee",
"name" : "Delivery Fee",
"amount_money" : {
"amount" : 700,
"currency" : "USD"
},
"calculation_phase" : "TOTAL_PHASE"
}
]
}
}
This is the structure of the file.
{
"_id" : ObjectId("5f45274bbbe768fe0d56d9d0"),
"article" : "article-name",
"comments" : [
{
"id" : "_lj7cfhx7z",
"name" : "person",
"date" : "25/08/2020",
"text" : "asdasdsddsdsdasd",
"replies" : [
{
"name" : "person2",
"date" : "25/08/2020",
"text" : "replyyyteextttttt"
},
{
"name" : "person3",
"date" : "25/08/2020",
"text" : "replyyyteextttttt"
}
]
},
{
"id" : "_wpdpj7kv6",
"name" : "person4",
"date" : "25/08/2020",
"text" : "aaaa",
"replies" : [ ]
}
]
}
I am trying to write a function that appends to replies list given the id of the comment. When I do it in the MongoDB shell like this db.comments.findOneAndUpdate({"article": "exif-parsing", "comments.id": "_t2aqbhi5a"}, {"$push": {"comments.$.replies": {"text": "new"}}});, it works. But in Node.js it doesn't work.
var db = new DataBase("mongodb://localhost:27017/")
replyTo(article, id, name, comment) {
db.connect("blog", "comments", function(collection) {
var reply = {name: name, date: getCurrentDate(), text: comment};
collection.findOneAndUpdate({"article": article, "comments.id": id}, {"$push": {"comments.$.replies": reply}});
});
}
I have this data on mongodb in a table named "Alerts" in geojson format
[
{
"_id" : ObjectId("5be40b8099d5b81e6115d517"),
"title" : "Real-time earthquake",
"priority" : "high",
"status" : NumberInt("1"),
"extAlertData" : {
"type" : "Feature",
"properties" : {
"mag" : 4.11,
"place" : "12km S of Tres Pinos,
CA",
"time" : 1541163534230,
},
"geometry" : {
"type" : "Point",
"coordinates" : [
-121.3146667,
36.6801667,
6.48
]
},
"id" : "nc73105276"
}
}
{
"_id" : ObjectId("5be401c39b9e021a4c1a5c80"),
"title" : "Real-time earthquake",
"priority" : "high",
"status" : NumberInt("1"),
"extAlertData" : {
"type" : "Feature",
"properties" : {
"mag" : 4.5,
"place" : "107km NW of Tobelo,
Indonesia",
"time" : 1541665816710,
},
"geometry" : {
"type" : "Point",
"coordinates" : [
127.2763,
2.3671,
31.55
]
},
"id" : "us1000hp6t"
}
}
]
I want to retrieve the field "id" which is nested inside "extAlertData" and time using model query.
Expected Output :
[
{
id:'nc73105276',
time:'1541163534230'
},
{
id:'us1000hp6t',
time:'1541665816710'
}
]
Following query does not working.
db.Alerts.find({fields : {"extAlertData.id": true}},
function (err, Alerts){
//process alert extAlertData.id
}
});
Query is retrieving the following error:
TypeError: Cannot read property 'id' of undefined
How can I query using fields filter in mongoDB? I am using loopback framework of node js.
Thanks in advance.
var yourdata =[];
var cursor = db.collection('Alerts').find();
cursor.each(function(err, item) {
if (item != null) {
var yourid = item.extAlertData.id;
var yourtime = item.extAlertData.properties.time;
var pushdata = {id: yourid,time: yourtime};
yourdata.push(pushdata);
}
});
I've been pulling my head on this one for days...
I'm using Node.js to make http calls to Google maps REST API's
I need to go over records of locations in my database, and using the lat,lng - find the google location id or reference in a given resolution - say "country" or "administrative_level_1" for example...
I found these two rest calls to be the closest to what I need:
https://maps.googleapis.com/maps/api/geocode/json?
latlng=47.333333,13.333333
&sensor=false
&key=YOUR_API_KEY
&result_type=administrative_area_level_1
this call takes in lat,lng and the desired resolution and give back an accurate result, but with no id or reference...
This is the result json:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Salzburg",
"short_name" : "Sbg.",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Austria",
"short_name" : "AT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Salzburg, Austria",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 48.04121,
"lng" : 13.9965099
},
"southwest" : {
"lat" : 46.94347,
"lng" : 12.07669
}
},
"location" : {
"lat" : 47.80949,
"lng" : 13.05501
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 48.04121,
"lng" : 13.9965099
},
"southwest" : {
"lat" : 46.94347,
"lng" : 12.07669
}
}
},
"types" : [ "administrative_area_level_1", "political" ]
}
],
"status" : "OK"
}
the only other alternative I have so far is to use the autocomplete REST API like so:
https://maps.googleapis.com/maps/api/place/autocomplete/xml?
key=YOUR_API_KEY
&location=47.333333,13.333333
&sensor=false
&language=en
&types=(regions)
&input=Austria
The problem with this one is that since it is meant for autocomplete purposes, it is required to pass in the 'input' parameter and not just lat,lng which is better for me. It is better because the locations I am trying to process are in many languages and it would be a nightmare to specify for each record its languages.
This is the result json for the previous call:
I need to iterate on the predictions objects and found the ones in the resolution I'm looking for...
{
"predictions" : [
{
"description" : "Austria",
"id" : "e16f8e9f2a60f60a0881c41488ff3869e4f938a4",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"reference" : "CiQfAAAAF11VDI_p7OWWL8woW8cOfCDDeA0iE-NMQwQsbQhouSASECau8aTrkIVsiUcGrmnNHhwaFEmcUvCjjjsHRDznswqC_xeOYiBR",
"terms" : [
{
"offset" : 0,
"value" : "Austria"
}
],
"types" : [ "country", "political", "geocode" ]
},
{
"description" : "Lower Austria, Austria",
"id" : "03ea5cab0b5abe4cb16f66e9a42c27d040ce2b3c",
"matched_substrings" : [
{
"length" : 7,
"offset" : 6
}
],
"reference" : "CjQuAAAAznpNXppnhg3bl-36bfMr4tsQa3ZjJJWmtUuHIEzEy4RL9M_LeSGc8muP-_h_e89gEhCFjfuwyex9OA36skw8bD45GhQ14NncFQk-AHOILKC4IqEPe-XqDw",
"terms" : [
{
"offset" : 0,
"value" : "Lower Austria"
},
{
"offset" : 15,
"value" : "Austria"
}
],
"types" : [ "administrative_area_level_1", "political", "geocode" ]
},
{
"description" : "Vienna, Austria",
"id" : "f622c175d668fbf75e7488ddf7b1a04ecb667788",
"matched_substrings" : [
{
"length" : 6,
"offset" : 0
}
],
"reference" : "CjQnAAAAD88YSerev6ZNhRw6hI0P9g_Brsjzc_qN5PqKtugj7GXIMbhqKK1qvJXYprMFu67mEhDYSzeYQwEQFjnOxjb3SsxAGhTocUQpKtR1CoM7sYJJROGImDMQzQ",
"terms" : [
{
"offset" : 0,
"value" : "Vienna"
},
{
"offset" : 8,
"value" : "Austria"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Oberosterreich, Austria",
"id" : "5ecb86bf53005b6cd7499f660e2312089a955ced",
"matched_substrings" : [
{
"length" : 14,
"offset" : 0
}
],
"reference" : "CjQvAAAAgtYVlhBFCDPBgcJu_7CXHJ8ncd3m6IozPSg3YzaLL4kXVtQowpjx4kc2K-Tqm_0YEhCn4rEiM0MaChwBhkki0qu_GhRgpGKjjh4Hq4aN2n9jFjdfc-Xl8Q",
"terms" : [
{
"offset" : 0,
"value" : "Oberosterreich"
},
{
"offset" : 16,
"value" : "Austria"
}
],
"types" : [ "administrative_area_level_1", "political", "geocode" ]
},
{
"description" : "Austrian District, Gyumri, Shirak, Armenia",
"id" : "3948451df8a40142c1adeeeb4a969dc1c7d82d39",
"matched_substrings" : [
{
"length" : 7,
"offset" : 0
}
],
"reference" : "ClRCAAAANrMT8rQH819b7rtJiCbaq0XbDip8VuQCO7EvoIkVmg4xUyQtxGiFhm9sF52hTbtp8PjR-b0_dCLn-ZXceYfJJ64j1hwxbuthSHomBoGBphMSEPC8ZwPtn6dOrYb_duar-tcaFIFbhTX9HWS4UDzF2exZcw2YUh9o",
"terms" : [
{
"offset" : 0,
"value" : "Austrian District"
},
{
"offset" : 19,
"value" : "Gyumri"
},
{
"offset" : 27,
"value" : "Shirak"
},
{
"offset" : 35,
"value" : "Armenia"
}
],
"types" : [ "sublocality", "political", "geocode" ]
}
],
"status" : "OK"
}
The original data is derived from the geonames database we used. We are switching to use google maps API's in all sections of our applications hence I need to convert those to google location id's using the lat,lng and resolution only... names are out of my control since they are a given. and in many languages...
I'd appreciate it if you can point out a REST API call that is able to do that or a sequence of http calls for that matter...
Appreciate it.
Ajar
Based on the API picker from the Google web site, I would suggest the following API:
Convert the latitude/longitude coordinates of a geographic location to an address (reverse geocoding).
Google Places API (a web service)
I have the following document:
{
"_id" : ObjectId("503b83dfad79cc8d26000004"),
"pdfs" : [
{
"title" : "Test document",
"pdf_id" : ObjectId("504f6793ce351a595d000004"),
"created_at" : ISODate("2012-09-11T16:32:19.276Z")
},
{
"title" : "Some other doc",
"pdf_id" : ObjectId("502bf124b4642341230003f0"),
"created_at" : ISODate("2012-09-11T11:34:19.276Z")
}
]
}
Now in an incoming form via req.body, I have 2 fields: title and description.
I want to update title and insert description for a specified pdf_id, how do I do that?
So in the end, my document will now look like:
{
"_id" : ObjectId("503b83dfad79cc8d26000004"),
"pdfs" : [
{
"title" : "This is an UPDATED title",
"description" : "It has an ALL NEW description",
"pdf_id" : ObjectId("504f6793ce351a595d000004"),
"created_at" : ISODate("2012-09-11T16:32:19.276Z")
},
{
"title" : "Some other doc",
"pdf_id" : ObjectId("502bf124b4642341230003f0"),
"created_at" : ISODate("2012-09-11T11:34:19.276Z")
}
]
}
Just to be clear, I'm really just looking for the Mongoose update syntax.
You can use the $ positional operator to refer to the matched pdfs array element in your $set:
Model.update(
{ 'pdfs.pdf_id': pdf_id },
{ $set: {
'pdfs.$.title': title,
'pdfs.$.description': description
}}, function (err, numAffected) { ... }
);