Skip Navigation

[Resolved] Find by distance not working consistently

This thread is resolved. Here is a description of the problem and solution.

Problem:
I had received a warning email from Google saying that the API was unrestricted and the key was potentially open to abuse. So, the sensible thing to do seemed to be to restrict it to the website URL. However, this seems to be causing the problem.

How can I protect the API key without breaking the functionality of Toolset maps?
Solution:
You can add a key with restrictions (URL referrer restrictions) as the first key, and an unrestricted key as the second key. More info:
- https://toolset.com/course-lesson/creating-a-maps-api-key/#problems-with-displaying-markers-on-google-maps
- https://stackoverflow.com/questions/35288250/google-maps-javascript-api-referernotallowedmaperror

Further, here is a related ticket where one of ours user solved the issue about http referer:
- https://toolset.com/forums/topic/google-maps-api-validation-restriction-error/#post-1809879

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 4 replies, has 3 voices.

Last updated by simonC-7 1 year, 8 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2575309

***I am trying to:
Perform a search based on distance. But some locations do not show listings within the miles stipulated, instead it shows all listings at all distances

***Link to a page where the issue can be seen:
hidden link

***I expected to see:

Results based on distance from the location chosen.

Instead, I got:

If I leave the distance at 5 miles, type in HP13 for the location > Personal Policy > Health Insurance, it wrongly shows all listings at any distance. Clearly these are not within 5 miles of the location chosen.

If I do the same but for the location HP12 it correctly shows the 2 listings.

It is behaving incorrectly like this for other random locations that I try too eg:
RG1 - ***incorrectly displays all listings at any distance***
50 miles - Birmingham, UK - ***displays correctly***
50 miles - Birmingham, UK, Grayswood Road, Longbridge, Birmingham, UK - ***incorrectly displays all results at any distance***

#2576241

Christopher Amirian
Supporter

Languages: English (English )

Screenshot 2023-03-19 at 13.24.37.png

Hi there,

I checked with HP13 and it gives me two locations attached to the screenshot.

Would you please test it with another browser or clear your browser cache?

Also please be aware that there is a bug in the Google Maps API that might contribute to the issue:

https://toolset.com/errata/search-by-distance-may-produce-wrong-results/

Thanks.

#2576715
Screenshot 2023-03-20 at 11.06.38.png

Thanks Christopher, I have temporarily resolved the issue by logging into Google API and removing the restriction Website restriction.

I had received a warning email from Google saying that the API was unrestricted and the key was potentially open to abuse. So, the sensible thing to do seemed to be to restrict it to the website URL. However, this seems to be causing the problem.

How can I protect the API key without breaking the functionality of Toolset maps?

#2577151

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Thanks for your reply.

You can add a key with restrictions (URL referrer restrictions) as the first key, and an unrestricted key as the second key. More info:
- https://toolset.com/course-lesson/creating-a-maps-api-key/#problems-with-displaying-markers-on-google-maps
- https://stackoverflow.com/questions/35288250/google-maps-javascript-api-referernotallowedmaperror

Further, here is a related ticket where one of ours user solved the issue about http referer:
- https://toolset.com/forums/topic/google-maps-api-validation-restriction-error/#post-1809879

Can you please try to follow that and check if that helps? Thank you, please let me know.

Regards,
Mateus.

#2577825

Many thanks Mateus,

Restricting the first key to domain.com and using an unrestricted 2nd key worked.

Note to others... only setting the domain to domain.com worked for me, adding http:// or https:// caused it not to work. I have read multiple comments in the links above where it worked for some and not others.