How to Use

You'll want to use the simplest approach for getting visitor geolocation data nearly 100% of the time. However, there may be some extremely rare edge cases where you need to override the service and/or ip values at runtime.

# Basic

{% set visitor = googleMaps.getVisitor() %}  {# As a normal method #}
{% set visitor = googleMaps.visitor %}       {# As a magic property #}

By default, the getVisitor method will:

  • Automatically detect the visitor's IP address.
  • Automatically use the lookup service specified by the plugin settings.

Perfect Example

The vast majority of the time, the above example is all you will need. Assuming you don't need anything more complex from your visitor geolocation call, just stick with the example above.

# Advanced

The getVisitor method is simple, yet flexible. You can override the ip or service values at runtime.

# getVisitor($config = [])

Arguments

  • $config (array) - Optional config settings to override the following:
Option Type Default Description
ip string (autodetects) The visitor's IP address.
service string (uses setting) Which geolocation service to use.

Returns

Visitor - A Visitor Model representing the approximate location of a visitor.

{% set visitor = googleMaps.getVisitor({
    'service': 'maxmind',
    'ip': '1.2.3.4',
}) %}

This allows you to manually specify the service and/or ip.

Supported Geolocation Services

At this time, the only accepted values are ipstack, maxmind, or false. Additional third-party geolocation services may be added in the future.

Low Precision Guaranteed

Regardless of which third-party service you are using, geolocation is an imprecise science.

A geolocation result will very often point to a user's internet service provider, or other internet routing equipment. While that location may be in the general region of the user, do not expect a geolocation result to point directly at a user's real location.