Filtering out entries with invalid coordinates

Smart Map has been replaced by Google Maps

Please install the Google Maps plugin instead. ➡️

As of February 2021, the Smart Map plugin has been completely rebuilt and replaced with the new Google Maps plugin for Craft CMS. For more details, see here...


The documentation below is for historical reference only.

You can pass a hasCoords parameter to show only locations with valid coordinates...

{% set params = {
    hasCoords: true
} %}

{% set entries = craft.entries.myFieldHandle(params).all() %}

The resulting entries will exclude any locations that did not have a valid set of coordinates. Coordinates are only valid if both the latitude and longitude values are populated.

# PHP

This can also be done in PHP...

use craft\elements\Entry;

$entries = Entry::find()
    ->section('mySection')
    ->myFieldHandle([
        'hasCoords' => true
    ])
    ->all();