Can't get 'distance_meters' field from react-native-google-places-autocomplete query - react-native

In the documentation for the Google API (https://developers.google.com/maps/documentation/places/web-service/autocomplete), it says that if you use the 'origin' param with a (latitude, longitude) value, it should return the field 'distance_meters'.
When I put the api call into my browser (https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=Ar&types=establishment&origin=40.70823656815506,-73.94331559793082&key=<API_KEY>) I do get the 'distance_meters' field, as you can see at the bottom of the image.
However, when I add the same params into the 'query' prop of the GooglePlacesAutocomplete component in react-native, I only get back a few of the fields shown above, and I do not get the 'distance_meters' field.
Please advise me on how to get the 'distance_meters' field using the GooglePlacesAutocomplete field. My code is below, I am console logging the rowData from renderRow.

When you check the GooglePlacesAutocomplete.d.ts source file of the react-native-google-places-autocomplete library, scroll to see the interface Query and you will notice that the origin parameter is not yet included in the library
// #see https://developers.google.com/places/web-service/autocomplete
interface Query<T = AutocompleteRequestType> {
key: string;
sessiontoken?: string;
offset?: number;
location?: string;
radius?: number;
language?: Language;
components?: string;
rankby?: string;
type?: T;
strictbounds?: boolean;
// deprecated. see https://github.com/FaridSafi/react-native-google-places-autocomplete/pull/384
types?: T;
}
In addition, to see all the Autocomplete predictions results, you can use the renderDescription function and log the data since this function determines the data passed to each renderRow (search result).
renderDescription={(data) => console.log(data)}
Here's a sample code where you will see that the distance_meters is not returned since the origin parameter is not defined in the Query interface.
You can file the issue on the github repository here.

Related

Autodesk PDF Extension - Preventing page in query string override

I'm currently looking to implement pagination within the ForgeViewer PDF Extenstion, in the documentation there's a note that 'page' in the querystring will override any value passed to load model. I wondered if this was configurable or we were able to prevent this.
// URL parameter page will override value passed to loadModel
viewer.loadModel(‘path/to/file.pdf’, { page: 1 });
This is causing us a few issues as we use 'page' for other purposes and we'll have to rework quite a bit to rename our current page querystring which we're using for paginating tables.
That's correct. If you look inside the PDF extension's code (https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/extensions/PDF/PDF.js) then you'll find that this behaviour is hardcoded unfortunately 😞
I can think of two workarounds:
a) Use a URL param other than page - e.g. sheet?
b) Overwrite the current URL so that the page number will become what you need
// Original URL is: http://127.0.0.1:5500/index.html?page=2
// we change it to page=1
// This should change the URL content without a reload
history.pushState('', '', 'index.html?page=1');
viewer.loadModel("AutoCAD_Sample_Part1.pdf", {}, (model) => {
You could also achieve the same like this:
viewer.loadExtension('Autodesk.PDF').then(function(ext) {
// Original URL is: http://127.0.0.1:5500/index.html?page=2
// we change it to page=1
viewer.loadModel("AutoCAD_Sample_Part1.pdf", {}, (model) => {
ext.hyperlinkTracker.changePage(1)

Cypress Get Attribute value and store in Variable

I want to get the Attribute value and store in a variable how we can achieve this in cypress
In my case I want to get the complete class value and store it in variable.
This code just give me the attribute class value but how I can store the fetch value in variable
cy.get('div[class*="ui-growl-item-container ui-state-highlight ui-corner-all ui-shadow ui-growl-message"]').invoke('attr', 'class')
I was trying to compare the style of one element with another to make sure they were equal. Here's the code that seems to work for me.
cy.get('.searchable-group-selector-card-image')
.eq(4)
.invoke('attr', 'style')
.then(($style1) => {
const style1 = $style1
})
A good way to solve this kind of scenario is to use the alias mechanism. One could leverage this functionality to enqueue multiple elements and then check all of them together by chaining the results. I've recently come to a case in an SPA where the assertion had to happen between elements that were spread across different angular routes (call them different pages).
In your use case, this would like:
cy.get('.searchable-group-selector-card-image')
.eq(4)
.invoke('attr', 'style')
.as('style_1')
cy.get('.another-element')
.invoke('attr', 'style')
.as('style_2')
// later on for example you could do
cy.get('#style_1').then(style_1 => {
cy.get('#style_2').then(style_2 => {
// Both values are available and any kind of assertion can be performed
expect(style_1).to.include(style_2)
});
});
This is described in Variables and Aliases section of the Cypress Documentation.
Here is how I got the value of for attribute in a label tag which had text "Eat" inside.
cy.contains('Eat').then(($label) => {
const id = $label.attr('for');
}
Most important thing is to get the selector right, so it exactly finds the value you are looking for. In this case you already found it. By using then() gives you the ability to store it in a variable.
cy.get('div[class*="ui-growl-item-container ui-state-highlight ui-corner-all ui-shadow ui-growl-message"]').invoke('attr', 'class')
.then($growl-message => {
const message = $growl-message.text()
//do the checks with the variable message. For example:
cy.contains(message)
})
Note that the scope of the variable is within the curly brackets. Thus using the variable has to be within those curly brackets.

What is Object details in Chrome.* API

I am learning Chrome extension development from the official documentation and learned a bit but I need understanding what it means by object details in API function parameters. For example one of browserAction method getTitle signature is
chrome.browserAction.getTitle(object details, function callback)
//object details integer (optional) tabId
Now I write in background.js
chrome.browserAction.getTitle({}, titleShow);
function titleShow(t){
console.log('tab title:' + t);
}
and it show title of my extension.As you can see here I send blank object {}.
How do I get tabId on very first line and send it with this method?
Does this method return tab Title if we send tab id?
You are asking questions that are easy to answer, just check the documentation and you'll see the details of the chrome.browserAction.getTitle() method (and all the other methods of the Chrome APIs).
Quoting from the documentation:
chrome.browserAction.getTitle(object details, function callback)
Gets the title of the browser action.
Parameters:
object details:
integer (optional) tabId. Specify the tab to get the title from. If no tab is specified, the non-tab-specific title is returned.
function callBack. The callback parameter should be a function that looks like this: function(string result) {...};
string result.
So, to answer your questions:
To get the tab id on the first line you've got to use the chrome.tabs.query() method (see documentation), request the tab with the details you're interested in and use its ID in the callback, something like this:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.browserAction.getTitle({tabId: tabs[0].id}, function(result) {
console.log("Browser action title:", result);
});
});
Browser actions can have different titles on different tabs. To set a different title for each tab you have to use the chrome.browserAction.setTitle() method. So if you send the tabId in the details object of the chrome.browserAction.getTitle() method, you'll not get the tab title, you'll only get the tab-specific title of the browser action. To get a specific tab title you should use the chrome.tabs.query() method.

Can't obtain iteration 'Theme' in Rally app (2.0RC3)

I'm modifying the IterationSummary app from the 2.0RC3 SDK, and adding more iteration info to it. For some reason, I am not able to retrieve the 'Theme' for the iteration, although I am able to query for other fields from the iteration object. Starting with the sample, I simply added the following lines #192
{
cls: 'theme',
html: iteration.get('Theme')
},
I can get 'Name' but I can't get the 'Theme' value even though it is clearly set on the iteration, and I verified that value using the REST API to query that same iteration. And querying other fields such as 'Name' works well. Any idea why 'Theme' is not being returned?
Do you fetch 'Theme' ?
You may see a general example that builds a grid of iterations that fall within a release (selected in the releasecombobox) that has Theme column populated as long as an iteration has a theme entered is in this github repo.
This example is different from the IterationSummary app because in my example I explicitly create Rally.data.wsapi.Store for Iteration object and fetch Theme.
Customizing the IterationSummary app will still require explicit fetching of Theme field, but you are correct that it is not obvious from the IterationSummary app how other fields are being fetched, e.g. State of iteration. The iteration object in that app is returned from this.getContext().getTimeboxScope().getRecord() and if you print out that object in the console, theme will be empty. The fields that exist on this.getContext().getTimeboxScope().getRecord() are limited and cannot be customized for performance reasons.
In order to modify this app to display Theme, the Iteration model has to be accessed and Theme fetched explicitly. Here are the steps I took to modify the app:
added getTheme function:
getTheme: function(){
var iteration = this.getContext().getTimeboxScope().getRecord();
return iteration.self.load(iteration.getId(), {
fetch: ['Theme']
});
}
In rc3 every time when we have a record, .self will give its model, so there is no need to do this manually:
Rally.data.ModelFactory.getModel({
type: 'Iteration',
//...
Note fetch: ['Theme']
Next, inside _addContent method getTheme() is called
return Deft.Promise.all([this.getTheme(), this.calculateTimeboxInfo()]).then({
success: function(results) {
var theme = results[0].get('Theme');
and then finally theme variable's value is passed to:
{
cls: 'theme',
html: theme
}
The full code is available in this github repo.

AngularJS: Take a single item from an array and add to scope

I have a ctrl that pulls a json array from an API. In my code I have an ng-repeat that loops through results.
This is for a PhoneGap mobile app and I'd like to take a single element from the array so that I can use it for the page title.
So... I'm wanting to use 'tool_type' outside of my ng-repeat.
Thanks in advance - I'm just not sure where to start on this one.
Example json data
[{ "entry_id":"241",
"title":"70041",
"url_title":"event-70041",
"status":"open",
"images_url":"http://DOMAIN.com/uploads/event_images/241/70041__small.jpg",
"application_details":"Cobalt tool bits are designed for machining work hardening alloys and other tough materials. They have increased water resistance and tool life. This improves performance and retention of the cutting edge.",
"product_sku":"70041",
"tool_type": "Toolbits",
"sort_group": "HSCo Toolbits",
"material":"HSCo8",
"pack_details":"Need Checking",
"discount_category":"102",
"finish":"P0 Bright Finish",
"series_description":"HSS CO FLAT TOOLBIT DIN4964"},
..... MORE .....
Ctrl to call API
// Factory to get products by category
app.factory("api_get_channel_entries_products", function ($resource) {
var catID = $.url().attr('relative').replace(/\D/g,'');
return $resource(
"http://DOMAIN.com/feeds/app_productlist/:cat_id",
{
cat_id: catID
}
);
});
// Get the list from the factory and put data into $scope.categories so it can be repeated
function productList ($scope, api_get_channel_entries_products, $compile) {
$scope.products_list = [];
// Get the current URL and then regex out everything except numbers - ie the entry id
$.url().attr('anchor').replace(/\D/g,'');
$scope.products_list = api_get_channel_entries_products.query();
}
Angular works as following:
Forgiving: expression evaluation is forgiving to undefined and null, unlike in JavaScript, >where trying to evaluate undefined properties can generate ReferenceError or TypeError.
http://code.angularjs.org/1.2.9/docs/guide/expression
so you only need to write:
<title>{{products_list[0].tool_type}}</title>
if there is a zero element the title will be the tool_type, if not, there is no title.
Assuming you want to select a random object from the list to use something like this should work:
$scope.product-tool_type = products_list[Math.floor(Math.random()*products_list.length)].tool_type
Then to display the result just use
<h1>{{product-tool_type}}</h1>
Or alternatively:
<h1>{{products_list[Math.floor(Math.random()*products_list.length)].tool_type}}</h1>