simplemap icon indicating copy to clipboard operation
simplemap copied to clipboard

sorting on distance doesn’t work using googme maps api

Open MarkOlijslagers opened this issue 6 years ago • 2 comments

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

  • Craft version: 3.3.13
  • Maps version: 3.7.1
  • PHP version: 7.2.24
  • Database driver&version: MySQL 5.5.64 --

MarkOlijslagers avatar Oct 31 '19 12:10 MarkOlijslagers

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 avatar Nov 02 '19 12:11 MarkOlijslagers

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

Tam avatar Nov 08 '19 15:11 Tam