Xamarin forms - Country by Location - xamarin.forms

I'm trying to get the country of the user using the location. Is there a library or API that can help me with this? And if not, where do you think I can start?
Thanks,

this is called "Reverse Geocoding" and can be done using Essentials
var lat = 47.673988;
var lon = -122.121513;
var placemarks = await Geocoding.GetPlacemarksAsync(lat, lon);
var placemark = placemarks?.FirstOrDefault();
if (placemark != null)
{
var geocodeAddress =
$"AdminArea: {placemark.AdminArea}\n" +
$"CountryCode: {placemark.CountryCode}\n" +
$"CountryName: {placemark.CountryName}\n" +
$"FeatureName: {placemark.FeatureName}\n" +
$"Locality: {placemark.Locality}\n" +
$"PostalCode: {placemark.PostalCode}\n" +
$"SubAdminArea: {placemark.SubAdminArea}\n" +
$"SubLocality: {placemark.SubLocality}\n" +
$"SubThoroughfare: {placemark.SubThoroughfare}\n" +
$"Thoroughfare: {placemark.Thoroughfare}\n";
Console.WriteLine(geocodeAddress);
}

Related

Write to Spreadsheet in Google sheet from ASP.NET

I have a code, it should write in the Spreadsheet of google sheet. When I run the function, I receive this error:
Message[Requested writing within range ['6/12/2019-20:37'!A1], but
tried writing to column [B]] Location[ - ] Reason[badRequest]
Domain[global]
That its my code:
private void SheetPattern(Item webinar)
{
var valueRange = new ValueRange();
var range = $"{sheet}!A:D";
DateTime dateTime=(DateTime)webinar.webInfo.times[0].startTime;
var date = dateTime.Day+"-"+dateTime.Month+"-"+dateTime.Year;
var hour = dateTime.Hour + ":" + dateTime.Minute;
var webName = webinar.webInfo.subject;
var webDescription = webinar.webInfo.description;
var oblist = new List<object>() { date, hour, webName, webDescription};
valueRange.Values = new List<IList<object>> { oblist };
var appendRequest = service.Spreadsheets.Values.Append(valueRange, SpreadsheetId, range);
Console.WriteLine(appendRequest);
appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
var appendReponse = appendRequest.Execute();
}
I found the problem its a Syntax problem, here:
var hour = dateTime.Hour + ":" + dateTime.Minute;
when I make a new sheet with a new name, google sheet doesn't permit the char : in the sheet name. So I change this code for that code:
var hour = dateTime.Hour + "-" + dateTime.Minute;

how cloud masking is done on Landsat 8 surface reflectance data in Google earth engine?

I want to download cloud-masked Landsat 8 surface reflectance collection from google earth engine. I don't have any idea how to perform a cloud masking algorithm. here's my code:
Map.centerObject(table);
Map.addLayer(table);
var sur = ee.ImageCollection.load('LANDSAT/LC08/C01/T1_SR')
.filterBounds(table)
.filterDate('2013-01-01','2019-11-01')
.filter(ee.Filter.equals('WRS_PATH',15))
.filter(ee.Filter.equals('WRS_ROW',33))
.filter(ee.Filter.lt('CLOUD_COVER', 5))
//.filter(ee.Filter.equals('IMAGE_QUALITY',4))
//.filter(ee.Filter.rangeContains('CLOUD_COVER',15,45));
.filter(ee.Filter.lt('CLOUD_COVER_LAND', 5));
print(sur);
// list of images (client side)
var imColl_sur = sur.getInfo().features;
print('features: ', imColl_sur);
print('length: ', imColl_sur.length);
// loop on client side
for (var i = 0; i < imColl_sur.length; i++) {
var id = imColl_sur[i]["id"];
var im = ee.Image(id);
var clip = im.clip(table);
var b1 = clip.select('B1');
var D_T = imColl_sur[i]["properties"]["SENSING_TIME"];
var sza = (imColl_sur[i]["properties"]["SOLAR_ZENITH_ANGLE"]).toString();
Export.image.toDrive({
image: b1,
description: id.slice(8, 12)+"_surReflectance_B1_"+ id.slice(28, 34) +"_"+ D_T.slice(0,4)+D_T.slice(5,7)+D_T.slice(8,10) + "_" + D_T.slice(11,13)+D_T.slice(14,16) + "_" + sza.slice(0,2)+sza.slice(3,8),
scale: 30,
region : table,
maxPixels : 1e9
});
}
thanks
You should check out this example provided by the Earth Engine team: https://code.earthengine.google.com/?scriptPath=Examples:Cloud%20Masking/Landsat8%20Surface%20Reflectance
This script uses the pre-computed Landsat 8 QA band from CFMask to remove clouds and cloud shadows.

Is there a way to use a script to pull a date from a Google Form submission from sheets into Gmail?

I have no experience with script writing, but I was able to find a script and edit it (with lots of trial and error) to fit my need.
I have a Google Form where the first question allows users to select a date, but it is not necessarily the date users are completing the form. The results export to a Google Sheet, and I have a script that sends an email with the form responses.
It worked beautifully until Daylight Savings Time. Now, the dates in the spreadsheet are correct, but in the emails they are one day off.
Example email message:
Your child, NAME, received a dress code violation on Wed Mar 27 2019
23:00:00 GMT-0600 (CST), for No ID.
Before Daylight Savings Time, the time was showing as 00:00:00.
In the code, row[2] is the date pulled from the spreadsheet.
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script");
var startRow = 2;
var numRows = 5000;
var dataRange = sheet.getRange(startRow, 1, numRows, 5000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[12];
var message = "Your child, " + row[10] + ", received a dress code violation on " + row[2] + ", for " + row[11] + ".\nIf you have any questions, please email NAME at name.name#name.org\n\nThank you,\n\nNAME\nAssistant Principal";
var emailSent = row[13];
if (emailSent != EMAIL_SENT) {
var subject = "Uniform Violation - Do Not Reply";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
Ideally, the email would provide the date exactly from the spreadsheet in MM/DD/YYYY format.
Instead, the emails show the previous day with the time of 11 pm.
Try this:
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var ss=SpreadsheetApp.getActive();//added this
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script");
var startRow = 2;
var numRows = 5000;
var dataRange = sheet.getRange(startRow, 1, numRows, 5000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[12];
var message = "Your child, " + row[10] + ", received a dress code violation on " + Utilities.formatDate(new Date(row[2]),ss.getSpreadsheetTimeZone(), "MM dd, yyyy HH:mm:ss" ) + ", for " + row[11] + ".\nIf you have any questions, please email NAME at name.name#name.org\n\nThank you,\n\nNAME\nAssistant Principal";//modified this
var emailSent = row[13];
if (emailSent != EMAIL_SENT) {
var subject = "Uniform Violation - Do Not Reply";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
You will probably have to change the dates format.
Date Format

Displaying Date and Time information in script with format from spreadsheet

I'm working on a basic email-sending script in Google Sheets. I want to send email reminders on clicking a button, reminding people of an appointment at a date and time along with the location.
Everything works, except for the date is displayed in a confusing long form format:
The data shown in the date and time cells is:
8/27/2018
10:30 AM
The data being sent in the email is:
Mon Aug 27 2018 15:00:00 GMT+0800 (HKT)
Sun Dec 31 1899 02:30:00 GMT+0800 (HKT)
I only need to show the date and time as written in the sheets. Is there a way to do this?
Another question is that one person might have more than one appointment, can I combine all appointments date/time for each unique email address into one email instead of multiple emails?
Adding code below:
function sendArticleCountEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("SSname"));
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange("B2:O2");
var data = dataRange.getValues();
for (i in data) {
var rowData = data[i];
var emailAddress = rowData[0]; //email
var recipient = rowData[1]; //name1
var message2 = rowData[2]; //Name2
var message3 = rowData[3]; //type
var message4 = rowData[4]; //Appt Date
var message5 = rowData[5]; //Appt Time
var message6 = rowData[6]; //Appt type
var message7 = rowData[7]; //Notes
var message8 = rowData[8]; //Facility Name
var message9 = rowData[9]; //Facility Address
var message10 = rowData[10]; //City
var message11 = rowData[11]; //Zip
var message12 = rowData[12]; //Phone
var message13 = rowData[13]; //Service
var message = 'Dear ' + recipient + ',\n\n' + 'This is a friendly reminder of your assignment tomorrow with:' + '\n\n' + message2 + ' at ' + message5 + '.'
+ '\n\n' + 'The assignment is located at ' + message8 + ', ' + message9 + ', ' + message10 + ', ' + message11 + '.' + '\n\n'
+ 'This assignment is noted as a ' + message6 + ' ' + message3 + ' ' + message13 + '. ' + message7 + '\n\n';
var subject = 'Reminder: ' + message4 + ' ' + message5 + ' (' + message2 + ')';
MailApp.sendEmail(emailAddress, subject, message);
}
}
I think the problem is here, using either var or rowData. The row is correct, just it doesn't pull the data in as shown in Sheets.
var message4 = rowData[4]; //Appt Date
var message5 = rowData[5]; //Appt Time
There is no time in the DATE cell (8/27/2018), so I'm guessing it defaults to "15:00:00" and because my data is input by mailparser, I don't have a method to change the format of the data. Rather I hope I can use the data as displayed in Google Sheets and display this into the Gmail.
I appreciate your suggestions in advance, thanks!

Firebase function transaction handle null value

I'm trying to use firebase function transaction, but as I see there is no official way to handle the first cached null value...
I'm trying to do the following:
var team = event.data.child('team').val();
var tip = event.data.child('tip').val();
console.log('tip: ' + tip + ' | team: ' +team)
const pathToValue = admin.database().ref('users/' + event.params.userId + '/coins');
const pathToTeamBetsValue = admin.database().ref('matches/' + event.params.matchId + '/opponents/' + team + "/bets");
return pathToValue.transaction(function (coins) {
if (coins) {
if (coins >= tip) {
pathToTeamBetsValue.transaction(function (teamBets) {
if (teamBets) {
teamBets = teamBets + tips;
return teamBets;
}
});
admin.database().ref('bets/' + event.params.matchId + '/' + event.params.userId + '/status').set('inProgress');
coins = coins - tip;
}
else {
console.warn(event.params.userId + " new bet on match " + event.params.matchId + " was not successfull! (not enough coin)")
//return coins;
}
}
return coins;
})
so far as you can see I get some value which what should be decreased from the user's coins... unfortunately till now I could only get the behaviour which sets null in the user's coin value.. please help

Resources