Forum

Thread tagged as: Question, Runway

Collection Question

I am using Runway to build a collection that will contain store locations to be output with a jquery store locator plugin.

My question is about using a custom sql query to output the results from the form submission.

Here is an example from the storelocator plugin docs to show what I need to achieve.

$locations = $db->query("
SELECT * FROM locations
WHERE lat BETWEEN  $origLat - DEGREES(0.0253) AND  $origLat + DEGREES(0.0253)
AND lng BETWEEN $origLng - DEGREES(0.0253) AND $origLng + DEGREES(0.0253)
LIMIT 100
");

I need to add DEGREES around the Lat and Long variables submitted when filtering the data in the collection.

Can I do this within perch_collection() or do I need to access the data another way.

Thanks.

Paul Sturrock

Paul Sturrock 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

What format does the plugin actually need the data in? What is the output you need to have?

I will be outputting to JSON

Drew McLellan

Drew McLellan 2638 points
Perch Support

Use perch_collection() with the skip-template option, or the headless API.

If I use either of those methods I am still using the perch query system and so I am unsure as to how to add in the DEGREES to limit the data returned.

Ideally I would not return all 2000+ stores for each search request. DEGREES allows me to limit the the returned data to a 100mile (or what ever I wish) square around the submitted LAT & LONG. Is that doable? Or does it require some custom SQL query?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you want to store and query data in a custom format then you'd need to implement that as an app. You can't use collections to do that.

OK. Thanks for letting me know. Is there general access to a Perch 3 sample app available yet? Last time I looked in the docs it was still Perch 2.

Just noticed there is upgrade advice now available. Will check it out.

Have had a look at the updated docs for the API. Is there any expanded documentation available for $HTML as the API docs are still referencing old docs.

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support