I am developing an application on ReactNative, which works over geoquery. Simply, I am getting data with the help of geoquery then showing in FlatList.
But the problem is that I am using an state of array as,
this.state = {
data: []
}
How to add the keys I am getting from geoquery in this state of array.
I am using geoquery as,
geoQuery.on('key_entered', (key, location, distance) => {
console.log(key + " entered query at " + location + " (" + distance + " km from center)");
})
I want to add key getting from geoquery to an state of array, then get data of related key from firebase with the help of state of array containing key.
As per my understanding from your question, you can do something like below:
geoQuery.on('key_entered', (key, location, distance) => {
console.log(key + " entered query at " + location + " (" + distance + " km from center)");
this.setState({data: [...this.sate.data, key]});
})
Related
In my application I show the route between point A to point B.
final PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(ContextCompat.getColor(mContext, R.color.accent_color));
polyOptions.width(20);
polyOptions.addAll(currentRoute.getPoints());
In currentRoute.getPoints I have all LatLng used to draw route on map. I extract all points that have 5km distance between them into a ListArray named points.
Now I want to populate along this route with locations from my database. I need to display all locations from my database that are on route or near it on 5km limit (on both sides of route).
For that I need to go to database and filter the records to find all locations that are in 5km range. I don't know how to implement WHERE request for location_latitude and location_longitude to can get all records that are on 5km range to reference location.
My current SQL is:
query = "SELECT location_id, location_name, " +
"location_address, location_image, " +
"location_latitude, location_longitude, " +
"c.category_marker, l.category_id " +
"FROM tbl_categories c, tbl_locations l " +
"WHERE l.category_id " + " = " + categ + " AND l.category_id = c.category_id AND " +
"location_county " + " = \"" + county + "\"";
Any suggestion how to filter faster my database (sql query) to find all locations near route?
I gone to this way:
where_query = new StringBuilder();
for (i = 0; i <= points.size()-1 ; i ++) {
if (i == 0) {
where_query.append(" AND ((location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append(")");
} else {
if (i < points.size() - 1) {
where_query.append(" OR (location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append(")");
} else {
where_query.append(" OR (location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append("))");
}
}
}
Waiting suggestions!
When victory line chart display the x-axis labels, the labels are on one line and I would like to display the label with text-wrapping. See the two images below to see what it is doing currently and what I would like for it to do.
Currently What is Happening
The image below is what I would like to happen. What I would like
I have created a function in the tickFormat to provide custom label text and that part is working.
<VictoryAxis fixLabelOverlap={true} tickFormat={t => this.formatLabel(t)} />
formatLabel = (t) => {
var x = new Date(t);
var s = x.getHours() + ":" + x.getMinutes() + (x.getMonth() + 1) + '/' + x.getDate();
return s;
}
You should be able to create a new line with a line break "\n"
formatLabel = (t) => {
var x = new Date(t);
var s = x.getHours() + ":" + x.getMinutes() +'\n'+ (x.getMonth() + 1) + '/' + x.getDate();
return s;
}
How I am performing a SQL query to insert data into the database. Note that the field PlanDetails in the table dbo.Plans is a text field. However, when a user tries to input a sentence which contains an apostrophe (e.g. I'll go to sleep). via the HTML form . The database returns an error "Incorect syntax near ll), which refers to the apostrophe problem. In this case, how should I modify the code below to make it accept sentences with apostrophe? It is told that I can use parameterized queries. In this node js example, how can I do that?
CreatePlan : function (newPlan , UserID, DisplayName, Email, callback) {
var sql = require('mssql');
var config = require('./configuration/sqlconfig');
var conn = new sql.Connection(config);
var req = new sql.Request(conn);
conn.connect(function (err) {
if (err) {
console.log(err);
return;
}
console.log('Attempting to Insert new learning plan...');
req.query('INSERT INTO dbo.Plans (PlanTitle, PlanTopic, OwnerID, OwnerName, PlanDetails, TargetLearners, OwnerContact) VALUES ("' + newPlan.PlanTitle + '", "' + newPlan.PlanTopic + '", "' + UserID + '", "' + DisplayName + '", "' + newPlan.PlanDetails + '", "' + newPlan.TargetLearners + '", "' +Email+ '");', function (err) {
if (err) {
console.log(err);
} else {
console.log("Added one new learning plan");
console.log("The new plan title is " + newPlan.PlanTitle);
callback();
}
conn.close();
});
});
},
In SQL (and in many other languages), you have to escape special characters to avoid any ambiguity in the code. There is a lot of documentation about how to escape and which character are concerned all other internet.
Here is the wikipedia article about escape character: https://en.wikipedia.org/wiki/Escape_character
Here is a stackoverflow post that answer your question: How do I escape special characters in MySQL?
However I should warn you about SQL injection, the code you are using will not be safe and you should probably take a look at the good practice in this matter.
I have a taxonomy index that describes a tree structure. When performing a query I want to get the number of hits for multiple categories (not necessarily in the same level of the tree). For example, given the following list of paths:
[Root/Cat1, Root/Cat1/Cat12, Root/Cat3]
I want to obtain the number of hits for each of these three categories.
I've been looking for a solution and I know that is possible to make a tree request and then get the results by calling .getSubResults() (as it is explained in the API). However I haven't found any example and I don't really know how to implement it. So far I've got to the following:
// Build query
Query query = extendQuery(queryGenerator.generateQuery(resource));
// Set the number of top results
TopScoreDocCollector tdc = TopScoreDocCollector.create(numTopDocuments, true);
// Set a faceted search
FacetSearchParams facetSearchParams = new FacetSearchParams();
// Search at level of the category in interests
CountFacetRequest facetRequest = new CountFacetRequest(new CategoryPath("Top", '/'), numTopCategories);
facetRequest.setResultMode(ResultMode.PER_NODE_IN_TREE);
facetSearchParams.addFacetRequest(facetRequest);
// To collect the number of hits per facet
FacetsCollector facetsCollector =
new FacetsCollector(facetSearchParams, documentReader, taxonomyReader);
try {
// Collect the number of hits per facet
documentSearcher
.search(query, MultiCollector.wrap(tdc, facetsCollector));
for (FacetResult res : facetsCollector.getFacetResults()){
//this is the top lvl facet
FacetResultNode toplvl = res.getFacetResultNode();
System.out.println(toplvl.getLabel() + " (" + toplvl.getValue() + ")");
for (FacetResultNode secondlvl : toplvl.getSubResults()) {
//second lvl facet categories
System.out.println(" " + secondlvl.getLabel().getComponent(1)
+ " (" + secondlvl.getValue() + ")");
for (FacetResultNode thirdlvl : secondlvl.getSubResults()) {
//second lvl facet categories
System.out.println(" " + thirdlvl.getLabel().getComponent(2)
+ " (" + thirdlvl.getValue() + ")");
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
However, when I get to the third level I get null. What is going on?
Thanks.
You have to set also:
facetRequest.setDepth(MAX_DEPTH_TREE);
I have an as3 app which utilises an sqlite db to save metrics data. It is well known that as3 is single threaded, so when I save to this db, the Stage Video I am playing becomes jumpy! I have heard that saving db data in batches can speed up this process so I save in a loop:
for (var i:int=0; i < metricsObject.metricsComponentData.length; i++){
switch (metricsObject.metricsComponentData[i].mouseType) {
case MetricsCollator.MOUSE_OVER:
this._query_txt = "INSERT INTO " + this._tablePath[0] + " VALUES (null, " + this._sessionID +
", " + metricsObject.metricsComponentData[i].timeStamp +
", '" + metricsObject.metricsComponentData[i].component + "'" + ")";
break;
case MetricsCollator.MOUSE_OUT:
this._query_txt = "INSERT INTO " + this._tablePath[1] + " VALUES (null, " + this._sessionID +
", " + metricsObject.metricsComponentData[i].timeStamp +
", '" + metricsObject.metricsComponentData[i].component + "'" + ")";
break;
} // end switch
executeQuery(this._query_txt);
} // end loop
I have looked into pseudo threading examples but they all require a sprite or stage instance, the class I am executing this code in, is not a display class, I don't really want to pass an instance of the stage into this class, seems dirty! ;-)
Anyone have any ideas?
Most examples of pseudo threading use a display object and an enter frame listener, but you can just as well use a Timer, or if your application has some kind of update loop that works too.
Here's a simple example using a Timer:
package {
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class PseudoThreadExample extends Sprite {
private var _timer:Timer;
public function PseudoThreadExample(){
// create a timer that runs with a low interval
// tweak this to fit your needs!
_timer = new Timer(30, 0);
_timer.addEventListener(TimerEvent.TIMER, handleTick);
}
public function startWorking():void {
// put work to be done in list here
// in your case that will probably mean making an array of SQL-
// statements to run later
_timer.start();
}
public function handleTick(event:TimerEvent):void {
// pop a thing off the list and do it.
// if list is empty, stop the timer
_timer.stop();
}
}
}