Flutter Geocoding address - flutter

I want to get coordinates and full/real address depending on what I write on a TextField.
From the geocoding Flutter package, i can see the following example :
List<Location> locations = await locationFromAddress("Gronausestraat 710, Enschede");
So i have tried to write "Paris" and call locationFromAddress("Paris").
But it doesn't find any result because the address is malformed.
When i was developping my Android app with Google maps, i could even write "Lond" and it was finding "London" (I am not speaking about the PlaceAutoComplete API).
When you search a location you don't want to have to write the full address...
So how can i achieve this simple use case in Flutter ?
Thanks !

You can use try this package
Sample code:
import 'package:geocoder/geocoder.dart';
final query = "1600 Amphiteatre Parkway, Mountain View";
var addresses = await Geocoder.local.findAddressesFromQuery(query);
var first = addresses.first;
print("${first.featureName} : ${first.coordinates}");
// From coordinates
final coordinates = new Coordinates(1.10, 45.50);
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");

Related

How do I display the data in flutter app?

Temperature=37 , humidity = 60 //data from api
String read =
"humblehacks.xyz/Server.php?patient=Yassen%20Mohamed&request=REQUEST_DATA_DAWNLOAD";
http.Response jread = await http.get(Uri.parse(read));
if (jread.statusCode == 200) {
var body = jread.body;
I am using api to get data , but not by json or xml just string ,
How do I show the data , I can't use Jsondecode because ABI is not Json
i want to display 37 and 60 in app , how can i display it I want full code
Output widgets like text should suffice
Text(37.toString()), // Simple value
Text("Temperature $val"), //String and variable
Text("Temperature ${temp.val}"),//String and map item

Get address and city name of a LatLng point using GoogleGeocoding Flutter

I am trying to get address and city name of a LatLng point using google_geocoding:
var googleGeocoding =
GoogleGeocoding("MY_KEY");
var result = await googleGeocoding.geocoding.getReverse(LatLon(lat, lng));
print(result?.results?.first.formattedAddress.toString());
The result of the print:
Corso Italia, 22-24, 20122 Milano MI, Italy
I need to get only Corso Italia, the string before the comma and Milano, how can I get that?
I tried to use addressComponents, but I only got numbers (especially if I select locations in countries like Italy)
print(result?.results?.first.addressComponents?.first.longName.toString());
It may not be the most optimal but you could play with picking the string through the spaces and then make the string in such a way that you can have the sequence you want

Searching sembast data both caps and small letters

I am using sembast package for local data storage for a flutter app. When I search through the local data, I want to get the results regardless of whether letters are in caps or small. My current code is sensitive to capital and small letters.
Future searchFoodByField(String fieldName, String searchItem) async {
var finder = Finder(filter: Filter.matches(fieldName, searchItem));
final recordSnapshots = await _foodStore.find(
await _db,
finder: finder,
);
return recordSnapshots.map((snapshot) {
final food = Food.fromMap(snapshot.value);
food.foodId = snapshot.key;
return food;
}).toList();
}
How can it be modified to get the desired outcome?
I'm assuming you want to look for the exact word. For non-english language, you might also want to remove the accent. (diacritic package can help help here).
// Using a regular expression matching the exact word (no case)
var filter = Filter.matchesRegExp(
fieldName, RegExp('^$searchItem\$', caseSensitive: false));
You can also use a custom filter, to perform any filtering you want:
// Using a custom filter exact word (converting everything to lowercase)
searchItem = searchItem.toLowerCase();
filter = Filter.custom((snapshot) {
var value = snapshot[fieldName] as String;
return value?.toLowerCase() == searchItem;
});

Name email attachment in Google Apps Script

I have the following G.A.S script to email a google sheet as a pdf attachment.
var spreadsheet = SpreadsheetApp.getActive();
var subject = spreadsheet.getRange("U1:U1").getValues();
var emailTo = spreadsheet.getRange("V1:V1").getValues();
var message = spreadsheet.getRange("W1:W1").getValues();
var pdf = DriveApp.getFileById(spreadsheet.getId()).getAs('application/pdf').getBytes();
var attach = {fileName:subject,content:pdf, mimeType:'application/pdf'};
MailApp.sendEmail(emailTo, subject, message, {attachments:[attach]});
The above code works well except that the file attached to the email message has a bizarre name like "[Ljava.lang.Object_#4e63998c" with no ".pdf" extension!
I am looking for a way to set a name for the pdf file before being attached to the email. The file name should equal the "subject" variable.
Thanks in advance.
Omid
Values retrieved by getValues() is 2 dimensional array. I think that the filename becomes such string because the array is used as the filename. Please retrieve the element from the array and try again. So could you please modify as follows?
From :
var attach = {fileName:subject,content:pdf, mimeType:'application/pdf'};
To :
var attach = {fileName:subject[0][0],content:pdf, mimeType:'application/pdf'};
You can also use the following modification. In this case, getValue() can retrieve the value as a string from the cell "U1".
From :
var subject = spreadsheet.getRange("U1:U1").getValues();
To :
var subject = spreadsheet.getRange("U1:U1").getValue();
Reference :
getValue()
getValues()
If this was not what you want, please tell me. I would like to think of other solutions.
I'm a bit late, but another way to solve this problem might be:
var spreadsheet = SpreadsheetApp.getActive();
var subject = spreadsheet.getRange("U1:U1").getValues();
var emailTo = spreadsheet.getRange("V1:V1").getValues();
var message = spreadsheet.getRange("W1:W1").getValues();
var pdf = DriveApp.getFileById(spreadsheet.getId())
.getAs('application/pdf')
.getBlob()
.setName(subject);
MailApp.sendEmail(emailTo, subject, message, {attachments:[pdf]});
The Blob class has a setName method https://developers.google.com/apps-script/reference/base/blob#setName(String), that can be chained into a Blob object (which is the result of getBlob())
After that you just need to add the Blob object inside attachments array of function MailApp.sendEmail

google auto complete retains the old values

I have implemented the google API for finding the cities of a particular Country selected.The Code is something like,
function initialize(ctryId) {
var ctyId = [];
ctyId.push(ctryId);
console.log(ctyId[0]);
var options = {
types: ['(cities)']
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input , options);
autocomplete.setComponentRestrictions({'country': ctyId});
google.maps.event.addListener(autocomplete, 'place_changed', function () {
selected = true
});
I am setting the country Id i.e ctyId in the above code from country dropdown.
This works fine for me.
But the issue is the old value is persisted.For example,If I select country as India and try for city autocomplete,it works perfectly fine but when I select some other country say Germany,the autocomplete options for city would include Indian cities as well.Is there anyway I can restrict the autocomplete options to the selected country only or to clear the old values.Thanks in advance.
Google API creates an element for drop down with class ".pac-container". Removing that element and creating it again works fine.
$(".pac-container").remove();