I am working on geo location search in nodejs backend. And mongodb is the database. In order to do that, I am getting values from front end. I am using map getbound to get viewport data. Below are some variables that holds latitude and longitude.
var topLeftLong = parseFloat(req.body.topLeftLong);
var topLeftLat = parseFloat(req.body.topLeftLat);
var topRightLong = parseFloat(req.body.topRightLong);
var topRightLat = parseFloat(req.body.topRightLat);
var bottomRightLong = parseFloat(req.body.bottomRightLong);
var bottomRightLat = parseFloat(req.body.bottomRightLat);
var bottomLeftLong = parseFloat(req.body.bottomLeftLong);
var bottomLeftLat = parseFloat(req.body.bottomLeftLat);
Though I am getting these data, I want to put latitude and longitude in an array. But whenever I tried to push data in the array, I get the below error.
Seems like wrong data type is to blame. In your code if you applied cast, for e.g. (int)string-var, then it could be the error due to that. Data types are important. Mismatch data types would cause errors.
Related
I am using Azure Maps and the javascript atlas library:
https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas?view=azure-maps-typescript-latest
Below code returns undefined when i access bbox property of Polygon class:
var hull = atlas.math.getConvexHull(positions);
var boundingBox = hull.bbox //returns undefined.
var polygon = new atlas.data.Polygon(positions);
var bBox = polygon.bbox //returns undefined even here.
Code which works is:
var boundingBox = atlas.data.BoundingBox.fromPositions(positions); //Works fine.
I need to calculate centroid from convex hull using:
var centroid = atlas.data.BoundingBox.getCenter(hull.bbox)
Can anyone please help me.
Thanks.
The bbox property of a feature is only defined if it was defined/calculated directly, often this is populated in GeoJSON files and thus would be populated when read in. By default the map does not populate this field if it isn't already populated as it would mean a lot of unnecessary calculations in majority of apps.
For your scenario you would do this:
var hull = atlas.math.getConvexHull(positions);
var boundingBox = atlas.data.BoundingBox.fromData(hull);
var centroid = atlas.data.BoundingBox.getCenter(boundingBox);
Here is a similar sample: https://azuremapscodesamples.azurewebsites.net/index.html?sample=Polygon%20labels%20-%20calculated
If you are looking to place a label on the center of the polygon, you might also want to consider this approach: https://azuremapscodesamples.azurewebsites.net/index.html?sample=Polygon%20labels%20-%20symbol%20layer
Currently, I'm working on processing information I've received from a JSON file, and as it's organized into multiple levels, I need to be able to convert not only the file, but all of its contents into the correct file types. I'm having some issues with this, and I can't find anything for Swift on this issue.
So far, I've tried the methods that are apparent within the code below. I couldn't find much information on alternate methods to do this, and I'm still new to programming, so I haven't been able to do much.
URLSession.shared.dataTask(with: urlRequest) { data, response, error in
if let data = data {
print("Clear")
let returnData = String(data: data, encoding: .utf8)
do {
let image = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
print(image!["results"])
var imgl2 = image!["results"]
imgl2 = imgl2 as! Array
//imgl2 = imgl2![0]
//print(imgl2!["color"])
// var imgl3 = imgl2!["results"]
// var imgl4 = imgl3!["results"]
// var imgl5 = imgl4!["results"]
// var imgl6 = imgl5!["results"]
} catch let error {
print(error)
}
}
}.resume()
What should happen here is that I should be able to convert the JSON's contents into the correct file types. To some extent, this works, and I'm able to obtain the first level of results. However, partway through the process at imgl2 = imgl2 as! Array, I can't convert it to an Array. Instead, I receive the error (Cannot assign value of type 'Array<_>' to type 'Any?'). I'd really like to be able to use the array enclosed, but I can't. After this, there will be several additional levels of content that I will need to sort through in this manner. I've tried looking at the API documentation, but I don't understand the way they've written it (this is Unsplash, by the way), and as such, I've tried this method. How exactly would I go about this?
(For further information, I'm trying to pull out the first image in the results, so that I can then edit it programmatically. I need the URL enclosed in the response to the search query, but the way the documentation is worded is unclear enough, and solutions to this problem so sparse, that I've had to use trial and error to get to where I am. Any insight into how to accomplish this would be greatly appreciated.)
Cannot assign value of type 'Array<_>' to type 'Any?
The error tells you that imgl2 is of type Any?, but you're trying to assign it a value of type Array. Swift doesn't allow changing the type of a variable after it has been initialized. What you could do is to assign imgl2 as! Array to a new variable to avoid this error.
I also suggest you to have a look at Decodable protocol to create models corresponding to the JSON structure.
json image
i am trying to get json object value but did not get
json = JSON.parse(json);
alert(json.observations[0].dateCorrect);
Your json is probably wrongly encoded. The actual key is "observations[0].dateCorrect". See matching quotes:
So you'll have to do json['observations[0].dateCorrect'] to get what you want, but you better (if you can) change how json is encoded first.
To make it clearer:
var data = JSON.parse(json);
var key = 'observations[0].dateCorrect';
alert(data[key]);
that's coz the thats not JSON, this is a string you need to parse it before accessing it.
try this
var obj = JSON.parse(json);
alert(obj.observations[0].dateCorrect);
I need is to dynamically add the points I’ve received from a forex provider to s Shield UI Chart. According to the documentation, there isn’t the possibility for dynamically adding of points At least there is no such method, something like: AddPoint or similar.
How can I still achieve a web page using Shield UI Chart, which to constantly show a couple of exchange rates?
You are right, that there is no addPoints method of the Shield UI Chart. However we can add the incoming data values to an array instead. You might find useful following code:
We need some arrays- as many as we need to show.
var EURUSD = new Array();
var USDCAD = new Array();
var GBPUSD = new Array();
In the body of the function, that will actually display the data we will have the following code:
EURUSD[EURUSD.length] = parseFloat(data.ticks.EURUSD);
USDCAD[USDCAD.length] = parseFloat(data.ticks.USDCAD);
GBPUSD[GBPUSD.length] = parseFloat(data.ticks.GBPUSD);
it will actually put the new data to the designated arrays. You can note, that each time data is received, it has been added to the last index of each array:
EURUSD.length
Since we don’t want our arrays to grow too large, it is good to specify how many points we need to keep. Once that limit is reached, we remove the oldest point:
if (EURUSD.length > 50)
EURUSD = EURUSD.splice(1, 49);
if (USDCAD.length > 50)
USDCAD = USDCAD.splice(1, 49);
if (GBPUSD.length > 50)
GBPUSD = GBPUSD.splice(1, 49);
At the end we need to recreate the chart, referencing the appropriate container:
var containter = $("#EURUSDChart").swidget();
containter.destroy();
and than create the chart again.
I am trying to pull data from an Entity called latLongInfo and trying to get all the results with the lattitude results within a certain range. Below code should work but it's not:
Filter lowerLatF = new FilterPredicate("lat", FilterOperator.GREATER_THAN, botLat);
Filter topLatF = new FilterPredicate("lat", FilterOperator.LESS_THAN, topLat);
Filter twoFilter = CompositeFilterOperator.and(lowerLatF, topLatF);
Query rip = new Query("latLongInfo").setFilter(twoFilter);
PreparedQuery ripQ = datastore.prepare(rip);
List<Entity> llResult = ripQ.asList(FetchOptions.Builder.withLimit(15));
int sizeOfList=llResult.size();
The value of botLat is 40.94495459565217 and the value of topLat is 41.3797372043.
In the Datastore that I am pulling the data from there's a result with lat = 41.1623459 however, the code above doesn't find it and keeps giving me a sizeOfList = 0.
I should be getting at least one result but it's not returning it. Is there something simple I am missing?
I figured this out. I was saving the lat as String rather than a numerical float or double. Once i changed it to save doubles (these were actually converted to floats in the datastore) I was able to do the comparison without issue.
Decided to answer my own question...in case this helps anyone else.