simplemap
simplemap copied to clipboard
sorting on distance doesn’t work using googme maps api
Description
Because the website (front+backend) gets really slow sometimes (using nominatim openstreetmaps and get cUrl errors) i changed the geocoding api to Google Maps. When using google maps api, sorting on distance doesn’t work anymore. After sorting al distances results in 0 km/miles.
Steps to reproduce
- A valid google maps api key is installed
- The example code of the docs is used to sort on distance
- after sorting the distance for all entries results in 0 km or miles
Additional info
- Craft version: 3.3.13
- Maps version: 3.7.1
- PHP version: 7.2.24
- Database driver&version: MySQL 5.5.64 --
After some more debugging, i found out the sorting on distance function is working fine, but the location search doesn't work for me with the google maps API key.
This search is working well:
{% set entries = craft.entries.locatie({
location: { lat: 51.6208196, lng: 5.4015683 },
radius:4000
}).orderBy('distance').all() %}
{{ location.locatie.distance }} returns a good result
But search by city or address return in a zero distance:
{% set entries = craft.entries.locatie({
location: 'Maidstone, Kent',
radius:4000
}).orderBy('distance').all() %}
{{ location.locatie.distance }} returns '0' for all entries.
When using Nominatim for Geocoding, both snippets are working fine.
@MarkOlijslagers Have you enabled the Places API and Geocoding API on your Google Maps API key?