catonthecouchproductions
asked on
HTML5 Geo - Show results nearby - via API data - location difference
Hey,
I am making a simple app to return snow conditions via an API that returns JSON. I cache this in a database. I am using HTML5 Geo to get the users location and so far that works, returning long/lat/city. What I have been trying to do now, is say if you're in Portland, ME. Show resorts around you, say within 40 miles or so.
What is the best way to do that? Some type of math for long/lat to find a radius? Then sort through JSON?
Query DB
Return JSON to an object
Sort through object (client side or server?)
Return results within the users location
Thanks,
Ryan
I am making a simple app to return snow conditions via an API that returns JSON. I cache this in a database. I am using HTML5 Geo to get the users location and so far that works, returning long/lat/city. What I have been trying to do now, is say if you're in Portland, ME. Show resorts around you, say within 40 miles or so.
What is the best way to do that? Some type of math for long/lat to find a radius? Then sort through JSON?
Query DB
Return JSON to an object
Sort through object (client side or server?)
Return results within the users location
Thanks,
Ryan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could I break up the queries?
Grab location -> Get state -> Only return say Maine -> calculate distance?
Or is there an easier way? Also, the trick with the above is I have the JSON stored in a mysql table:
ID
JSON_FEED
DATETIME
Would that make it harder to sort? I would have to manipulate the array and sort/remove say state X
Not sure if thats the best way.
Grab location -> Get state -> Only return say Maine -> calculate distance?
Or is there an easier way? Also, the trick with the above is I have the JSON stored in a mysql table:
ID
JSON_FEED
DATETIME
Would that make it harder to sort? I would have to manipulate the array and sort/remove say state X
Not sure if thats the best way.
If the data that is needed is stored in the JSON data; then it will have to be parsed out so it can be referenced in the query. the PHP and query look a little complex and it will probably need someone better at PHP/mysql than me, and having to parse the JSON before it goes into the database also requires a fair amount of skill to get it right.
Cd&
Cd&
ASKER
Could I query the DB:
Grab the row with the highest id (newest)
Store object for use
Filter through based on state (deconstruct JSON, GET state via param)
Calculate distance
Send back
Perhaps?
Grab the row with the highest id (newest)
Store object for use
Filter through based on state (deconstruct JSON, GET state via param)
Calculate distance
Send back
Perhaps?
I don't know, I don't really work with JSON. When I have had to process JSON packages I generally am using some snippet design for the particular task. I think you are going to have to pull out the latitude and longitude as well. The calculations need to be done server side; I think. They can be done client side with Javascript, but JS is not the world's best number cruncher especially with float arithmetic.
Cd&
Cd&
ASKER