PHPackages                             vaersaagod/locate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. vaersaagod/locate

ActiveCraft-plugin[Search &amp; Filtering](/categories/search)

vaersaagod/locate
=================

Harness the power of the Google Autocomplete API inside Craft. Adds an autocomplete search box to Craft entries.

4.0.0(1y ago)24021MITPHPPHP ^8.2.0

Since Feb 10Pushed 1y ago3 watchersCompare

[ Source](https://github.com/vaersaagod/locate)[ Packagist](https://packagist.org/packages/vaersaagod/locate)[ RSS](/packages/vaersaagod-locate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (14)Used By (0)

Locate plugin for Craft CMS 5.x
===============================

[](#locate-plugin-for-craft-cms-5x)

Harness the power of the [Google Autocomplete API](https://developers.google.com/maps/documentation/javascript/places-autocomplete) inside Craft. Adds an autocomplete search box to Craft entries which allows place and address queries to be made to the API. Populates a hidden **Location** field with `lat`, `lng`, `location`, and `placeid` which you can grab in your templates to do with as you wish.

Requirements
------------

[](#requirements)

- [Craft CMS](https://craftcms.com/) 5.0.0 or later.
- [Google API key](https://developers.google.com/maps/documentation/javascript/get-api-key) with the Google Maps JavaScript API, Places API and Geocoding API enabled.

#### Note:

[](#note)

Google has updated their API access policy. See

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require vaersaagod/locate

    ```
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Locate, or from the command line:

    ```
     ./craft plugin/install locate

    ```
4. Configure the plugin via the plugin settings page in the control panel.
5. You can now create `Location` fields and add them to your entries.

Configuration
-------------

[](#configuration)

Navigate to Settings &gt; Plugins &gt; Locate. Enter your Google API key if you already have one, or [get one here](https://developers.google.com/maps/documentation/javascript/get-api-key). The settings page also allows you to customize the behaviour of the autocomplete box.

### Configuration settings

[](#configuration-settings)

#### `googleMapsApiKey`

[](#googlemapsapikey)

#### `apiLanguage`

[](#apilanguage)

#### `apiRegion`

[](#apiregion)

#### `autocompleteOptions`

[](#autocompleteoptions)

### Customize the autocomplete box

[](#customize-the-autocomplete-box)

The autocomplete search box need not be customized. It defaults to all place types (cities, addresses, businesses, etc.) in the world. By default, the API will attempt to detect the user's location from their IP address, and will bias the results to that location.

However, by passing in some basic options, advanced filtering can be achieved. You can modify the default behaviour by passing in a JSON object of options. For a full list of allowed options see the [official documentation from Google](https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete).

These options can be set globally or on a per field basis. Options set on individual fields will override the global options.

**The options object must be formatted correctly or the plugin will throw a javascript error! If after reading this documentation you are unclear about what to enter in the options box, please leave it blank.**

#### Restrict search by place type

[](#restrict-search-by-place-type)

You can specify an array of `types` to restrict the results returned to your autocomplete box. In general only a single type is allowed. Possible values are:

- `geocode`
- `address`
- `establishment`
- `(regions)`
- `(cities)`

See the [official documentation](https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete) for details on how using these `types` will restrict your results.

##### Example usage

[](#example-usage)

Restrict the results to cities:

```
"types": ["(cities)"]
```

Restrict the results to business establishments:

```
"types": ["establishment"]
```

#### Bias the search towards a geographical already

[](#bias-the-search-towards-a-geographical-already)

You can use the `bounds` property to specify a `google.maps.LatLngBoundsLiteral` and bias your search results to a geographic area. This is an object specifying `north`, `east`, `south`, and `west` values. The autocomplete box return results biased towards, *but not restricted to*, the area you specify.

See the [LatLngBoundsLiteral object specification](https://developers.google.com/maps/documentation/javascript/reference#LatLngBoundsLiteral) for full details.

Note that the values are entered as a *number* and not a *string*

##### Example usage

[](#example-usage-1)

Bias the search results to the Pacific Northwest:

```
"bounds": {
  "north": 50,
  "east": -122,
  "south": 48,
  "west": -123
}
```

#### Restrict search by country

[](#restrict-search-by-country)

You can restrict results to an individual country using the `componentRestrictions` property. The country must be passed as as a two-character, ISO 3166-1 Alpha-2 compatible country code.

##### Example usage

[](#example-usage-2)

Restrict the results to Canada:

```
"componentRestrictions": {
  "country": "ca"
}
```

#### Putting it all together

[](#putting-it-all-together)

Using the above examples we can create an options object that restricts searches to businesses in Canada, preferably in the Pacific Northwest region (ie. Starbucks in Vancouver).

```
"types": ["establishment"],
"bounds": {
  "north": 50,
  "east": -122,
  "south": 48,
  "west": -123
},
"componentRestrictions": {
  "country": "ca"
}
```

Using the Location field
------------------------

[](#using-the-location-field)

The Location field returns `locationData`, `lat`, `lng`, `location`, and `placeid`. You can use these in your templates and pass them on to your javascript.

- `locationData` returns the full API response from Google, with an additional `components` array which maps the `address_components` to an an array with the component types as keys. See [here](https://developers.google.com/maps/documentation/geocoding/intro#Types) for a list of some types. (For example, you can access `locationData.components.country` in your twig. You can also add `_short` to any component key to access the `short_name` of that address component, for example `locationData.components.country_short`).
- `lat` returns the latitude of the place
- `lng` returns the longitude of the place
- `location` returns autocomplete query
- `placeid` returns a textual identifier that uniquely identifies a place

The `placeid` can be used to make additional requests to the Google Maps API. With `placeid` you can make [place details requests](https://developers.google.com/maps/documentation/javascript/places#place_details_requests) to get information such as address, phone number, reviews, etc. You can also use the `placeid` to generate map markers. Read more about [referencing a place with a place ID](https://developers.google.com/maps/documentation/javascript/places#placeid).

### Templating examples

[](#templating-examples)

Using the options restrictions from the previous section, we could search for "Lucky's Donuts" in the autocomplete box.

```

  You searched for: {{ entry.myLocationFieldHandle.location }}

```

would generate the following:

```

  You searched for: Lucky's Doughnuts, Main Street, Vancouver, BC, Canada

```

You could then generate a simple map by loading up the Google Maps javascript API:

```

```

and grabbing the `placeid`, `lat`, and `lng` in your javascript:

```
var map,
    myLat = $('.yummy').attr('data-lat'),
    myLng = $('.yummy').attr('data-lng'),
    myPlaceId = $('.yummy').attr('data-place-id');

function initialize() {
  // Create a map centered at your location.
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: myLat, lng: myLng},
    zoom: 15
  });

  var myLatLng = new google.maps.LatLng({lat: myLat, lng: myLng});

  var marker = new google.maps.Marker({
    map: map,
    place: {
      placeId: myPlaceId,
      location: myLatLng
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
```

---

Price, license and support
--------------------------

[](#price-license-and-support)

The plugin is released under the MIT license. It's made for Værsågod and friends, and no support is given. Submitted issues are resolved if it scratches an itch.

Changelog
---------

[](#changelog)

See [CHANGELOG.MD](https://raw.githubusercontent.com/vaersaagod/locate/master/CHANGELOG.md).

Credits
-------

[](#credits)

Brought to you by [Værsågod](https://www.vaersaagod.no)

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 51.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Recently: every ~149 days

Total

13

Last Release

581d ago

Major Versions

v2.x-dev → 3.0.02022-04-24

v3.x-dev → 4.0.02024-10-05

PHP version history (3 changes)2.2.0PHP ^7.0

3.0.0PHP ^8.0.2

4.0.0PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2580dc72f65006fb038f68d3299615d97cdda269d0d487639a89cf2628b1176f?d=identicon)[vaersaagod](/maintainers/vaersaagod)

---

Top Contributors

[![mmikkel](https://avatars.githubusercontent.com/u/298510?v=4)](https://github.com/mmikkel "mmikkel (17 commits)")[![swixpop](https://avatars.githubusercontent.com/u/7113101?v=4)](https://github.com/swixpop "swixpop (12 commits)")[![aelvan](https://avatars.githubusercontent.com/u/2675644?v=4)](https://github.com/aelvan "aelvan (4 commits)")

---

Tags

craft-plugincraft3craftcmsaddressmapcmsCraftcraftcmscraft-plugingoogle mapslocatelocationsproximity-search

### Embed Badge

![Health badge](/badges/vaersaagod-locate/health.svg)

```
[![Health](https://phpackages.com/badges/vaersaagod-locate/health.svg)](https://phpackages.com/packages/vaersaagod-locate)
```

###  Alternatives

[swixpop/locate

Harness the power of the Google Autocomplete API inside Craft. Adds an autocomplete search box to Craft entries.

154.8k](/packages/swixpop-locate)[doublesecretagency/craft-googlemaps

Maps in minutes. Powered by the Google Maps API.

1267.9k](/packages/doublesecretagency-craft-googlemaps)[studioespresso/craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.

80136.8k](/packages/studioespresso-craft-scout)[trendyminds/algolia

Easily pull search results from Algolia into your Craft CMS website

1332.2k](/packages/trendyminds-algolia)[la-haute-societe/craft-elasticsearch

Bring the power of Elasticsearch to your Craft CMS projects.

1712.4k](/packages/la-haute-societe-craft-elasticsearch)[swishdigital/faceted-navigation

Provides faceted navigation of entries, using categories, which allows site users to narrow the list of entries they see by applying multiple filters (think Amazon or eBay left sidebar).

152.4k](/packages/swishdigital-faceted-navigation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
