If you need to lookup location components, country, and timezone data, you can use positionstack. The service is free to use!

laravel geocode

What is positionstack?

positionstack is a good service that is powered by scalable apilayer cloud infrastructure, handling billions of geocode requests with response times between 10 and 100 ms. The scalable API powers thousands of web applications and mobile apps worldwide and is affordable for anyone.

Features

position stack

Real-Time Geocoding

Geocode any global address or set of coordinates in real-time and look up location components, country and timezone data, and plenty more.

Scalable Infrastructure

The API is powered by scalable apilayer cloud infrastructure, handling billions of geocode requests with response times between 10 and 100 ms.

Worldwide Coverage

Take advantage of an extensive set of worldwide geocoding data, sourced from high-quality data vendors and updated multiple times per day.

Free to use

Send 10,000 monthly geocode requests for free.

Documentation

You can read the official documentation on the positionstack website.

How to use

Register to get a free API key

You need to go to positionstack and register to get a free API key.

Using Raw PHP

You can use raw PHP to identify user IP. Here is the sample code (which can be found at positionstack documentation):

Forward Geocoding:

$queryString = http_build_query([
  'access_key' => 'YOUR_ACCESS_KEY',
  'query' => '1600 Pennsylvania Ave NW',
  'region' => 'Washington',
  'output' => 'json',
  'limit' => 1,
]);

$ch = curl_init(sprintf('%s?%s', 'https://api.positionstack.com/v1/forward', $queryString));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$json = curl_exec($ch);

curl_close($ch);

$apiResult = json_decode($json, true);

print_r($apiResult);

Reverse Geocoding:

$queryString = http_build_query([
  'access_key' => 'YOUR_ACCESS_KEY',
  'query' => '48.2084,16.3731',
  'language' => 'ES',
]);

$ch = curl_init(sprintf('%s?%s', 'https://api.positionstack.com/v1/reverse', $queryString));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$json = curl_exec($ch);

curl_close($ch);

$apiResult = json_decode($json, true);

print_r($apiResult);

Using Node.js

Forward Geocoding:

const axios = require('axios');
const params = {
  access_key: 'YOUR_ACCESS_KEY',
  query: '1600 Pennsylvania Ave NW'
}

axios.get('https://api.positionstack.com/v1/forward', {params})
  .then(response => {
    console.log(response.data);
  }).catch(error => {
    console.log(error);
  });

If this post was helpful, please share this post with your friends and don't forget to follow our Facebook and Twitter pages!