Extracting distance from Google Maps DistanceMatrix API - flutter

I need to calculate the distance between coordinates.
I am using the Google Maps DistanceMatrix API:
getDistanceMatrix() async {
try {
var response = await Dio().get('https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${widget.miLatitud},${widget.miLongitud}&origins=${location.latitude},${location.longitude}&key=...');
print("distancia es ${response}");
} catch (e) {
print(e);
}
}
Which is the proper way to extract the distance from the response?
Here you have the response output:
distancia es {"destination_addresses":["Carrer de Sant Ramon, 62, 08140 Caldes de Montbui, Barcelona, Spain"],"origin_addresses":["Plaça de la Porxada, 32, 08401 Granollers, Barcelona, Spain"],"rows":[{"elements":[{"distance":{"text":"13.0 km","value":13012},"duration":{"text":"21 mins","value":1234},"status":"OK"}]}],"status":"OK"}

This is the beautified JSON file:
{
"destination_addresses":[
"Carrer de Sant Ramon, 62, 08140 Caldes de Montbui, Barcelona, Spain"
],
"origin_addresses":[
"Plaça de la Porxada, 32, 08401 Granollers, Barcelona, Spain"
],
"rows":[
{
"elements":[
{
"distance":{
"text":"13.0 km",
"value":13012
},
"duration":{
"text":"21 mins",
"value":1234
},
"status":"OK"
}
]
}
],
"status":"OK"
}
As you can see, you can get the distance if you go to rows-elements-distance-value, where you would get the result in meters.

Related

How make multiple detail bands to print data one after the other in Jaspersoft studio 6.12.2

I have a requirement to create an excel output using Json datasource in Jaspersoft. The expected excel output has 3 headers and under every heading, it has multiple rows of data. The data for every row is fetched from the parent and nested elements in the Json datasource. The rows under the first heading should complete printing before printing the next header and the data starts to print. please let me know if there's any way to create this jasper report without using subreports.
JSON:
[{
"id":"123",
"accountNumber":"123456",
"billingAddress":{
"addressLine1":"Test Address",
"addressLine2":"123 Test Lane",
"addressLine3":"Test Street",
"city":"Test City",
"state":"TST",
"zipCode":"12345"
},
"billingAnalystCode":"D2",
"billToId":"5947000000",
"billToDivisionNumber":"00000",
"billToGroupNumber":"59470",
"brand":"ABCD",
"coverageEndDate":"07/31/2020",
"coverageStartDate":"07/01/2020",
"customerType":"TEST",
"dualChoice":false,
"financialCompanyName":"XYZ",
"groupName":"XYZ TEST",
"groupSummary":[
{
"adjustmentAmount":0.0,
"amount":0.0,
"descriptionOfCharges":null,
"feeBasis":null,
"groupNumber":"59470",
"numberOfClaimsPaid":0,
"numberOfEnrollees":2,
"coverageOptions":[
{
"amount":0.0,
"amountDue":0.0,
"coverageOptionCode":"98",
"numberOfEnrollees":2,
"adminRatePerEnrollee":0.0,
"currentRate":0.0,
"premium":0.0
}
],
"divisionSummary":[
{
"divisionNumber":"00001",
"divisionName":"XYZ TEST",
"productCode":"EEPO",
"subGroupNumber":"59470",
"numberOfEnrollees":2,
"premium":0.0,
"totalAmount":0.0,
"amountDue":0.0,
"billedMemberDetails":[
{
"assignedId":"91246774200",
"firstName":"JOHN",
"lastName":"DOE",
"memberId":"321654987",
"supplierId":"5463213213",
"coverageEffectiveDate":"06/16/2014",
"coverageOptionCode":"98",
"effectiveDate":"06/16/2014",
"productCode":"EDPO",
"premium":0.0,
"amount":0.0,
"adjustment":null,
"currentAmount":"0"
},
{
"assignedId":" ",
"firstName":"LISA",
"lastName":"DOE",
"memberId":"654986541",
"supplierId":null,
"coverageEffectiveDate":"06/16/2014",
"coverageOptionCode":"98",
"effectiveDate":"06/16/2014",
"productCode":"EDPO",
"premium":0.0,
"amount":0.0,
"adjustment":null,
"currentAmount":"0"
}
],
"adjustedMemberDetails":[
{
"assignedId":" ",
"firstName":" ",
"lastName":" ",
"memberId":" ",
"supplierId":" ",
"coverageEffectiveDate":" ",
"coverageOptionCode":" ",
"effectiveDate":null,
"productCode":" ",
"premium":0.0,
"amount":0.0,
"adjustment":null,
"currentAmount":"0"
}
],
"ascSummary":{
"numEnrollees":"0",
"numberOfClaims":0,
"claimsPaid":0.0,
"adminRate":0.0,
"rateType":"0",
"adminFee":0.0,
"stopLossFee":0.0,
"adjustment":0.0,
"subtotal":0.0,
"cobraTotal":0.0,
"productCode":"0"
},
"coverageOptions":[
{
"amount":0.0,
"amountDue":0.0,
"coverageOptionCode":"98",
"numberOfEnrollees":2,
"adminRatePerEnrollee":0.0,
"currentRate":10.0,
"premium":101.0
},
{
"amount":0.0,
"amountDue":0.0,
"coverageOptionCode":"99",
"numberOfEnrollees":3,
"adminRatePerEnrollee":0.0,
"currentRate":20.0,
"premium":102.0
},
{
"amount":0.0,
"amountDue":0.0,
"coverageOptionCode":"100",
"numberOfEnrollees":4,
"adminRatePerEnrollee":0.0,
"currentRate":30.0,
"premium":103.0
},
{
"amount":0.0,
"amountDue":0.0,
"coverageOptionCode":"101",
"numberOfEnrollees":5,
"adminRatePerEnrollee":0.0,
"currentRate":40.0,
"premium":104.0
}
],
"fee":{
"adjustmentFee":0.0,
"adminRate":0.0,
"amount":0.0,
"claimsPaid":0.0,
"cobraTotal":0.0,
"enrolleeRoster":0.0,
"enrollmentAdjustmentsAmount":0.0,
"invoiceCapitation":0.0,
"invoiceMiscellaneous":0.0,
"invoiceOther":0.0,
"invoicePrefund":0.0,
"invoicePrefundDeposit":0.0,
"invoiceEqualizedDeposit":0.0,
"numberOfClaims":0,
"otherAdminFee":0.0,
"perEnrolleeTotal":0.0,
"settlementAdjustmentsAmount":0.0,
"stopLossFee":0.0,
"totalAmount":0.0
},
"enrolleeSummary":{
"totalNumberOfEnrollees":2,
"billedNumberOfEnrollees":0,
"unBilledNumberOfEnrollees":2,
"billedPremium":0.0,
"unBilledPremium":0.0,
"totalAmount":0.0,
"totalPremium":0.0
},
"adjustmentSummary":{
"totalAmount":0.0,
"numberOfEnrolees":0,
"premium":0.0
},
"billedSummary":{
"totalAmount":0.0,
"numberOfEnrolees":2,
"premium":0.0
}
}
],
"enrolleeSummary":{
"totalNumberOfEnrollees":2,
"billedNumberOfEnrollees":0,
"unBilledNumberOfEnrollees":2,
"billedPremium":0.0,
"unBilledPremium":0.0,
"totalAmount":0.0,
"totalPremium":0.0
}
}
],
"internalReferenceId":"BE003962799-2020-06-09",
"invoiceDate":"07/01/2020",
"invoiceNumber":"962799",
"invoiceSubType":"Premium",
"invoiceType":"Premium",
"perMemberPerMonthBilling":"PXM",
"publisherName":null,
"purchaseOrderNumber":null,
"statementTypeIdentifier":"DDFD-Premium",
"underWritingState":"33",
"invoiceAdminSummary":{
"invoiceEqualizedDeposit":0.0,
"totalNumEnrollees":null,
"totalNumClaims":null,
"totalClaimsPaid":0.0,
"totalAdminFee":0.0,
"totalStopLossFee":0.0,
"totalAdjustments":0.0,
"settlementAdjustmentsTotal":0.0,
"amountDue":0.0,
"invoiceOther":0.0,
"invoicePrefund":0.0,
"invoicePrefundDeposit":0.0,
"invoiceCapitation":0.0,
"invoiceMiscellaneous":0.0,
"invoiceCOBRATotal":0.0
},
"invoiceAmount":0.0,
"invoiceAmountDue":0.0
}
]
I have resolved the above scenario by placing the table components in the Summary band and having the 'float' property for all the tables except the first one.

Dutch postalcode in Mapbox Geocoding API

update it was a bug and they fixed it!
Dutch postalcodes contains 4 digits and 2 letters.
When entering 4 digits, it finds the global postalcode location, but when you add 2 letters (which corresponds to a street) the response doenst return the right location.
For example: 1012 returns a general postalcode location in Amsterdam. But when you enter 1012 AW it returns totally different results (different cities even). But it should return a specific location within the 1012 postalcode area.
url
https://api.mapbox.com/geocoding/v5/mapbox.places/${search}.json
params
{
language: 'nl',
country: 'NL',
limit: 1,
access_token: config.accessToken,
types: 'address,place,poi'
}
The postal code that comes back don't have the two letter digits. How to get Mapbox to add the two letters?
Example response.
It is 4694 but it should be 4694EG
{
"type":"FeatureCollection",
"query":[
"***",
"***"
],
"features":[
{
"id":"address.7144861498943104",
"type":"Feature",
"place_type":[
"address"
],
"relevance":0.75,
"properties":{
"accuracy":"point"
},
"text_nl":"Beatrixlaan",
"place_name_nl":"Beatrixlaan 2, 4694 Scherpenisse, Nederland",
"text":"Beatrixlaan",
"place_name":"Beatrixlaan 2, 4694 Scherpenisse, Nederland",
"center":[
4.103576,
51.546267
],
"geometry":{
"type":"Point",
"coordinates":[
4.103576,
51.546267
]
},
"address":"2",
"context":[
{
"id":"postcode.10605073597498580",
"text_nl":"4694",
"text":"4694"
},
{
"id":"place.5585596482812836",
"wikidata":"Q2381830",
"text_nl":"Scherpenisse",
"language_nl":"nl",
"text":"Scherpenisse",
"language":"nl"
},
{
"id":"region.13950781060383020",
"short_code":"NL-ZE",
"wikidata":"Q705",
"text_nl":"Zeeland",
"language_nl":"nl",
"text":"Zeeland",
"language":"nl"
},
{
"id":"country.9349515904622050",
"short_code":"nl",
"wikidata":"Q55",
"text_nl":"Nederland",
"language_nl":"nl",
"text":"Nederland",
"language":"nl"
}
]
}
],
"attribution":"NOTICE: © 2019 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."
}

Google chart breaks into two

I have given the data in the correct order. The render is somehow split between
2019 and 2018 and that too 2019 first and then 2018. Is there a fix for this? Or some property that causes this to happen?
The code is as follows:
import {GoogleCharts} from 'google-charts';
let graphRows = []
graphs[index].forEach(element => {
let dataArray = [];
dataArray.push(new Date(element["Date"].toString()));
dataArray.push(element['Net Asset Value']);
graphRows.push(dataArray);
});
//Load the charts library with a callback
GoogleCharts.load(drawChart);
function drawChart() {
// Standard google charts functionality is available as GoogleCharts.api after load
const data = new GoogleCharts.api.visualization.DataTable();
data.addColumn('date', 'Time');
data.addColumn('number', 'Net Asset Value');
data.addRows(graphRows);
// data.addRows(graphRowsReversed);
var options = {
hAxis: {
title: 'Date'
},
vAxis: {
title: 'Value'
},
explorer: { axis: 'horizontal' }
};
const line_chart = new GoogleCharts.api.visualization.LineChart(document.getElementById('chart-div'));
line_chart.draw(data, options);
}
graphs[index] is an array of objects each of which looks like this:
{
"Scheme Code": 145633,
"Scheme Name": "Mirae Asset Nifty 50 ETF (MAN50ETF)",
"ISIN Div Payout": {
"ISIN Growth": "INF769K01EG9"
},
"ISIN Div Reinvestment": "",
"Net Asset Value": 116.917,
"Repurchase Price": null,
"Sale Price": null,
"Date": "09-Apr-2019"
}

How to handle different languages with Google Actions and DiaglogflowApp with Firebase functions

I have configured multiple languages in my Dialogflow agent. I cannot figure out how to detect the language of the request in my firebase function in order to answer with the right language. Is there a standard approach to handle this? I don't see any function to detect the language in https://github.com/actions-on-google/actions-on-google-nodejs
I would expect to be able to do something like this:
const app = new DialogflowApp({request: request, response: response});
if (app.getLang == 'en') {
\\ Do something in english
}
else if (app.getLang == 'es') {
\\ Do something in spanish
}
There is a public sample on the AoG GitHub for Number Genie, which is in both French and English.
In this sample they define JSON objects for English and French locales:
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "cold genie",
"cardText": [
"Freezing like an ice cave in Antarctica?",
"I can't feel my face anymore",
"Hurry, before I turn into an icicle"
]
},
...
{
"images": {
"cold": {
"url": "COLD.gif",
"altText": "Génie froid",
"cardText": [
"Je me gèle comme un glaçon en Antartique",
"Je ne sens plus mon visage",
"Dépêchez-vous avant que je ne me transforme en glaçon"
]
},
...
Then there is a central strings.js file which will pull the correct string for that locale.
const i18n = require("i18n");
i18n.configure({
"directory": __dirname + "/locales",
"objectNotation": true,
"fallbacks": {
"fr-FR": "fr",
"fr-CA": "fr"
}
});
const prompts = () => ({
"welcome": {
"visual": {
"elements": [
[i18n.__("variants.greeting"), i18n.__("variants.invocation")],
i18n.__("variants.invocationGuess"),
i18n.__("images.intro")
],
"suggestions": onlyNumberSuggestions
}
},
...
Which is then used to map to each intent:
[Actions.GENERATE_ANSWER] () {
this.data.answer = strings.getRandomNumber(strings.numbers.min,
strings.numbers.max);
this.data.guessCount = 0;
this.data.fallbackCount = 0;
this.data.steamSoundCount = 0;
this.ask(strings.prompts.welcome, strings.numbers.min, strings.numbers.max);
}
The locale is set by getting that from the app.getUserLocale() method:
/**
* Get the Dialogflow intent and handle it using the appropriate method
*/
run () {
strings.setLocale(this.app.getUserLocale());
/** #type {*} */
const map = this;
const action = this.app.getIntent();
console.log(action);
if (!action) {
return this.app.ask(`I didn't hear a number. What's your guess?`);
}
map[action]();
}
There's definitely a lot here, and you don't need to do this exactly the same way. app.getUserLocale() should return the current locale, which you can then use in any way that you want to return the response.

Bot Framework - Facebook Prompt issue

I am using bot framework. I have my Facebook bot online and I am inspecting all the requests in my server. Sometimes my server is not receiving prompts answers (HeroCards buttons work perfect). If I retry and send a message many times, it works. If I use the emulator it works fine.
I wrote three times "pollo" to get the answer.
module.exports = (bot, builder, connector) => {
bot.dialog('/delivery', [
(session) => {
session.send('Bienvenido a 99UNO Delivery.');
let msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([
new builder.HeroCard(session)
.title('Pizza')
.subtitle('Todas nuestras pizzas.')
.images([
builder.CardImage.create(session, 'http://www.cateringolivia.com.ar/fotos/ser2_1g.jpg')
.tap(builder.CardAction.showImage(session, 'http://mx.cdn01.mundotkm.com/2016/01/e9a9d35c744f3ff11a97e32274411d8b_large.jpeg')),
])
.buttons([
builder.CardAction.imBack(session, 'Pizza', 'Seleccionar')
]),
new builder.HeroCard(session)
.title('Parrilla')
.subtitle('Carne, Pollo, Achuras.')
.images([
builder.CardImage.create(session, 'https://media-cdn.tripadvisor.com/media/photo-s/03/85/0c/c7/parrilla-tour-buenos.jpg')
.tap(builder.CardAction.showImage(session, 'https://restorando-res.cloudinary.com/image/upload/s--L2hhcZz2--/c_fit,f_auto,h_500,w_700/v1416341745/restaurant_photos/x/6939/52684/restaurante_parrilla-atahualpa_centro_10390894_1485980544972645_3906330496111888189_n.jpg')),
])
.buttons([
builder.CardAction.imBack(session, 'Parrilla', 'Seleccionar')
])
]);
builder.Prompts.choice(session, msg, 'Pizza|Parrilla', {listStyle: builder.ListStyle.button});
},
(session, results) => {
session.beginDialog('/' + results.response.entity.toLowerCase());
}
]);
bot.dialog('/pizza', [
(session) => {
builder.Prompts.choice(session, 'Qué gusto desea pedir?', 'mozzarella|napolitana|jamon', {listStyle: builder.ListStyle.button});
},
(session, results) => {
session.endDialog('Ya estamos llevando una pizza de ' + results.response.entity + ' a tu casa. Que lo disfrutes!');
}
]);
bot.dialog('/parrilla', [
(session) => {
builder.Prompts.choice(session, 'Qué desea pedir?', 'vacio|pollo', {listStyle: builder.ListStyle.button});
},
(session, results) => {
session.endDialog('Ya estamos llevando el ' + results.response.entity + ' a tu casa. Que lo disfrutes!');
}
]);
};
Server: Nodejs in Amazon ec2. Using morgan in index.js:
app.use(morgan(':method :url :status - [:date[clf]] - :remote-addr - :response-time'));
Any idea?