ethercreative / simplemap

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

sorting on distance doesn’t work using googme maps api #216

Open MarkOlijslagers opened 4 years ago

MarkOlijslagers commented 4 years ago

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

  1. A valid google maps api key is installed
  2. The example code of the docs is used to sort on distance
  3. after sorting the distance for all entries results in 0 km or miles

Additional info

MarkOlijslagers commented 4 years ago

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.

Tam commented 4 years ago

@MarkOlijslagers Have you enabled the Places API and Geocoding API on your Google Maps API key?