Вопрос

We've been using Google's Store Locator Example code since 2009 to provide the geographical search component for a simple, flat database of local voluntary organisations all providing roughly the same type of service to a geographical area in a single country, but not from a mappable point of presence.

The search volume is very low, the results are rows of plain text on a web page. It works.

So what's the problem?

When you've got system run by unpaid volunteers, you don't always have time to keep code up to date. And it seems overkill to be running a LAMP server or even shared hosting just to serve a singe page to search for "nearest 5".

Google Places Javascript API to the rescue!

Sounds a perfect fit for something like the JavaScript library component of Google Places API [FAQ].

The Places Search API even comes with a handy nearby method, using either radius or a bounded area. This would make a perfect Google web app, or possibly a page on our Google Apps for Non Profits service. No server to rent, no software to update.

And as a bonus, no messing with any CRUD - I can setup a simple Google Spreadsheet as the datasource, and anyone who can edit a spreadsheet can update the back-end details. Remember, we're only talking about max 5 results from 300 or so entries on a 5 column table. I've selectively pulled data from sheets 50x larger into Tabletop and presented the data with Handlebars without problems. Just not having to do a geo radius search.

But there's a catch.

To use the extremely neat and compact Places API methods, the data must actually already exist on Google Maps, and fit into one of a range of types. It wouldn't be correct to add our list of 300 or so service to Google Maps as businesses or services, as maps are for a specific location-based service, rather than a collection of outreaching-volunteers in a particular area. If we could find a way of combining the ease of the places API nearby radius search with a custom data source like the Maps API example, all problems would be solved. Except, I know of no such method. So...

The Question:

I want to allow searching of up to 5 results from a custom flat table in a 50 mile radius without needing the LAMP stack solution Google suggest in their 2009 pre-Places solution.

Am I on the right lines above but missing something obvious, or even not so obvious?
Or am I barking up the wrong tree here?

Guidance or nudges in the right direction are appreciated. Thanks.

Это было полезно?

Решение

Sounds like the Maps Engine API could work for you:

  • Stores your feature data in table format and offers GUI access to editing (though not as familiar as a spreadsheet).
  • Offers radius and bounds search on features.
  • Ability to limit the results to a specific number (you mentioned 5).
  • Returns GeoJSON which can be loaded into a Maps API app with the new Maps.Data object.
  • Free.

https://developers.google.com/maps-engine

So you could use jQuery to call your data:

https://developers.google.com/maps-engine/documentation/hello-world#javascript

using a query like:

https://www.googleapis.com/mapsengine/v1/tables/tableId/features
  ?intersects=CIRCLE(lng lat, radius)&limit=5&version=published&key=YOUR_API_KEY

So now you have a JSON object accessible to your JS. You can pass that JSON to Maps.Data:

https://developers.google.com/maps/documentation/javascript/datalayer

and also use it to populate any sidebar, infowindows, etc.

Might work for you?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top