I have a large database of items and they each have a location field which stores their longitude and latitude . I only want to display the items within 2KM to the users location .
Since my database is huge , creating an array by mapping through each database item and use getDistance from geolib is not very efficient . Is there any other way i can do this effectively .
Thanks any help will be appreciated
Related
I have an API for my e-commerce website which loads (80,000+ ) products along with category and brands ,, i want to call this api ( after every 1 or 2 min or maybe less ) and compare with my DB to keep my DB up to date and if any changes in any product in the API i have to update that in my DB ,,,
Currently I m loading all the data from api and using foreach loop and adding it to my DB , but it is taking too much time still i am not comparing the products after doing that the time to fetch data then compare and the save in DB will be too much.
what will be the best way to do this .
I have a list page where I have latitude and longitude data of different items. I want to add a filter function to restrict the items to a certain radius. But how can I do that with latitude and longitude data?
Have a look at the ngeohash npm package to store the hash code of the locations that you have and filter the data as in the below example.
https://levelup.gitconnected.com/nearby-location-queries-with-cloud-firestore-e7f4a2f18f9d
The above example using the firestore as a backend store but you also can use your own.
ngeohash npm link: https://www.npmjs.com/package/ngeohash
I am making a website where users can create routes on google maps and I have been looking around for the best way to store a path (the coordinates of there root) from google maps. I have found a few different options and I am not sure which is the best.
Should I
Store them in a JSON file then just store the path of the json file in a sql column? The only problem with that is I then cant make querys based off the coordinates in the json file.
or
Store every single latitude and Longitude point in a separate row? The only problem I see with this is one path on google maps could have over 1000 different points which would take up a lot of space in the database.
Any other ideas?
Store the points seperate in a table like this
coordinates table
-----------------
track_id
lng
lat
sequence_number --> you should also store a sequence to know the order in which you want to connect the coordinates
and another table containing the track info
tracks table
------------
id
name
other_stuff
If you then want to get all points of a track called My Bicycle Tour then run
select c.lng, c.lat, c.sequence
from coordinates c
join tracks t on t.id = c.track_id
where t.name = 'My Bicycle Tour'
order by c.sequence
Remember a DB can easily hold millions and even billions of records and with proper indexes this is also very fast to query.
I am trying to display a list of closest restaurants of a given city within a radius. In order to do this, I'll have to convert the city to a longitude/latitude.
When the user fills in his/her restaurant information, he/she will fill in the address. Based on that address i need to get a longitude/latitude and save that to the database.
I don't need to point this on a map. I'll be just displaying a list of all closest restaurants within the given radius to the user.
How can I do this with ASP.NET-MVC4?
Also, this project is based on Code First. And for address I have DbGeography as datatype set.
The project is kind of based on this tutorial
Edit
To avoid anyone else telling me this is not possible with ASP.NET on it's own, I am aware of that. an example with Google maps / .NET wrapper would be great.
This query itself is typically done in the database back-end because the program is the consumer of the data not the keeper of the data. You will have a table of restaurants, possibly for many cities, each restaurant having a latitude and longitude. You create a geospatial index on the table, which performs a tesselation for performance; you configure the tesselation parameters. You must determine the latitude/longitude of your restaurant-seeker's location. Your command object would feed that data to a stored procedure, along with the desired radius. The stored procedure would return an enumerable set of rows to your client program.
I found this .NET wrapper which fulfills my need.
I have a big problem with taking a simple Total Cost from an array!
I have an entity called currentCost, it contains two attributes: costAmount and costDesc. I bind it to an array controller and I have no problem when I add and remove items to and from this entity. The problem is to get the Total Cost from the costAmount attributes and show it in a text field.
I think I have to fetch all costAmounts to another array and take the total of them, but it seems I don't know how to do this! What is the best approach ?
Thank you in advance.
Bind the text field to the array controller and specify #sum.costAmount as the key path.