ethercreative / simplemap

A beautifully simple map field type for Craft CMS.
Other
137 stars 47 forks source link

Searching via address string doesn't return any results #296

Open Decipher-Webmaster opened 3 years ago

Decipher-Webmaster commented 3 years ago

Description

When carrying out a proximity search using an address string, no results are returned. However, when searching using co-ordinates, results are returned as expected. Here is an example snippet of the query I'm trying to implement:

{% set locationParam = craft.app.request.getParam('location') %}
{% set searchRadParam = craft.app.request.getParam('search-radius') ?? 100 %}

{% set retailersQuery = craft.entries().location({
    location: locationParam,
    radius: searchRadParam,
    country: 'UK',
    unit: 'mi'
}) %}

{% paginate retailersQuery as pageInfo, retailers %}

{% for retailer in retailers %}
    ...
{% endfor %}

The plugin is configured using 'Google Maps: Terrain' as the Map Style and 'Google Maps' as the GeoService. Both are confirmed to be working correctly via the Google Cloud Platform. When searching a comma-separated town & post code identical to that set in some example entries maps field, no results are returned. When searching the equivalent co-ordinates, all expected results are returned.

Steps to reproduce

  1. Add an entry containing a location field, add the address to the 'Maps' field and publish/save the entry.
  2. Execute maps proximity search query, with the location parameter set to an address string.

Additional info

ctigelaar commented 3 years ago

I had the same issue, but my problem was in the configuration of the Google API key used for the Geocoding API. The value of the "Application restrictions" was set to "HTTP referrers (web sites)" which means Craft CMS could not reach it (as a server). When you set it to "None" or "IP adresses (web servers, cron jobs, etc)", then Craft CMS is also possible to connect to the API.

I would expect though that SimpleMap would output some error logs on failures, but I couldn't find any in the logs of Craft CMS.

samhibberd commented 1 month ago

We have just run into this issue, problem is (please correct me if i'm wrong @Tam) but we can't currently work around it.

If you want to restrict access to the key (pretty important) then you have to set restrictions by either IP (for server side php requests) and referrer (client side js requests).

This requires two keys one for server side and one for client side and maps currently uses the same key for both, as a result we can't add restrictions if we want both to work, which we really need to do please.