Calculate distance between list of origin-destination using google api - google-distancematrix-api

I have a requirement to calculate the distance between the list of origin and destinations.
Say list has o1-d1, o2-d2, o3-d3 etc.
Is there a way to send all at a time to Google API and get all results instead of single o-d iterating in a loop for the size of the list.
thanks

I'm afraid that the answers is NO.
For now the API is design to give you only this format of response and the way to go is parsing throw it [1].
[1]https://developers.google.com/maps/documentation/javascript/distancematrix#distance_matrix_parsing_the_results

Related

Fuzzy matching a list of coordinates (Golang)

I'm trying to create a simple tool which will allow a user to specify two places around Seattle.
I'm working with the WSDOT traffic data set. An example of the output can be found here: https://gist.github.com/jaxxstorm/0ab818b300f65cf3a46cc01dbc35bf60
What I'd like to be able to do is specify two locations like:
Bellevue
Seattle
and then lookup all traffic times for those locations.
I'm considering doing a reverse geocode like this answer but I want it to be "fuzzy" in that I don't want people to have to specify exact locations. I also suspect the processing time for this might be long as I'd have to loop through the list, and reverse lookup all the coordinates which could take a short while
Is there any better alternatives for processing this data in this way? I'm writing the tool in Go
You have two problems for each set of points (start and end):
Convert locations to lat lon
Fuzzy match lat,lon to this traffic data (which contains lat,lon)
The location to lat,lon conversion is pretty straightforward using a reverse geocoding api like the one available from google.
To match lat,lon fuzzily, you could either truncate lat lon and store that as a hash (so that you're storing approximate matches), then lookup data that way, or you could do a radius calc and pick results within that radius (this requires some math involving the radius of the earth which you can look up easily enough, it can be done in sql if your data is in a db for example).

How to structure an efficient GeoLocation and Time query

Hey rethinkers!
i've got a query optimization question that i cant quite figure out. It deals with geoLocation and time. I've got a ton of events, that all have a startTime, endTime (indexed), and location (indexed). If i want to get the events that are happening nearby by a certain location that haven't happend yet, i can do one of two ways:
I can get and filter all the events that haven't happend yet based on the end time, then calculate the location of all those events and only return the ones with the specified radius.
I can use the getNearest() command (which would return all the expired events) and then filter out the events that haven't happend yet. My one worry with this apporach is that getNearest() specifies how many to return, but I essentially need all of them within the given radius so i don't miss any events that haven't happend yet.
Im just unsure how i can figure out the fastest/most effecient query for this.
The best option to me would seem to be to filter and get all events that haven't happend yet, then use getNearest() to take advatage of the indexes. But i can call a get nearest on a filtered set. Please help!?!?!
For getting all events within a radius, I recommend using getIntersecting() together with r.circle.
That is not only more efficient than getNearest, but also doesn't have any limit on the number of returned documents.
You might need to make the radius you pass into r.circle slightly larger, to account for the fact that the generated polygon will be slightly smaller than the specified radius between the vertices.

node.js serverside 2d search performance

I plan to store and update user locations (lat, lon, userid) via websocket on a nodejs server.
my goal is to broadcast the user locations to every user, as fast as possible.
(like the mytaxi position of each taxi in the app)
my concerns / problems
server side performance on lots of simultanious users
pushing the data back (i only need to know about users in my region)
-> 2d search (get users which lat / lon is in boundingbox )
questions:
whats the best storage solution (mongodb vs js array / object storage)
is read/write on db faster than array searching?
is there a 2d optimized javascript search solution?
my way
i would go for two arrays (arr1 sorted by lat, arr2 sorted by lon)
-> search via divide and conquer -> check on similar ids -> output
is there a better way to do this?
thanks in advance
alex
you can use Redis's pub/sub channels, create a channel for each bounding box and subscribe users to the relevant channels according to their location report, then push messages to entire channels.
this strategy may be naive for big data..

Find the State given Latitude and Longitude Coordinates

I have a set of 900 Latitude and Longitude Coordinates-- I need a relatively simple method for finding the 'State' referred to by these coordinates. If it helps, the data is in excel.
Google provide a Geocoding service. Part of this is reverse geocoding which converts geographic coordinates into a human-readable address including States. This Demo illustrates what can be done. There are limits to what you can do with this service.
Try to use the average values as provided here. With a bit of luck, most of your 900 coordinate pairs belong to the state with the nearest center. Calculation of distances between longitude/latitude locations is explained here.
An alternative would be to use a ZIP table with US postcodes as provided here. Once you know the postcode, you know the state, don't you? I'm not sure, but each state has an interval of ZIP codes. Once you know the ZIP code of a location, you can find the interval and the state it belongs to.
A list of coordinates of US locations could help to get a more exact allocation: http://www.bcca.org/bahaivision/fast/latlong_us.html
Find the nearest location in the list and take its state as result.
Google requires that geocoding / reverse geocoding be used with maps that users can see, so if that isn't an option for you, I think the best way is to use a database with spatial functions. First, you'll need the state boundaries found for free at NationalAtlas.gov. I use SQL Server (need 2008 or 2012 versions) and you can use the STContains() method to find what state it belongs to.
A simpler solution would be to just use the ezcmd.com rest API services.
They provide two APIs:
http://ezcmd.com/apps/app_geo_postal_codes#geo_postal_codes_api
1) All you have to do is just give it a zip code and a country code (for usa you either use US or USA) and optionally you'll pass the distance radius, and units (Miles or Km) and it'll return all other zip codes with state and province that are within the given distance
2) Free search, where you give it any fuzzy search phrase that includes either one of zip / city / state / province and country and it returns the best matches for that search phrase.
Hint: You can use #2 to find the zip code for a fuzzy (human readable) address and pass that zip code to #1 to find nearest places to that zip code.
Also they have another API that returns zip code along with full geo location information for a given IP address here:
http://ezcmd.com/apps/app_ezip_locator#ezip_locator_api
Enjoy ! I hope this helps.

How to show nearest store based on zipcode

I am creating an app tha is for a a bussines that has several stores around the state.
How can i show the information for the nearest sores based in the zip code?
Thanks for any help
The basic idea is:
Convert the ZIP code to geographical coordinates (longitude and latitude).
Compute the distance of each store to this coordinate.
Order the results by distance, ascending.
Step 2 can be optimized a bit -- for example, you might limit the search to those stores in the same state. You may also want to limit the number of stores returned if you are only going to display 10, for example.
This is about all the detail I can provide since your question is quite general.

Resources