MATLAB Geocoding Tutorial

Alexander Dentler has created two MATLAB functions, one for forward geocoding - called OpenCageForward and one for reverse called OpenCageReverse Please find the code for each in the opencage-matlab repository on Github.

%%  INIT
clear
clc
close all

%%  Parameters
key='YOUR-API-KEY';

%%  Forward search
q='Prinsengracht 263-267, 1016 GV Amsterdam, Netherlands';
%   plain search with one result
[results]=OpenCageForward(key,q);
%   first result gives us longitude and latitude of the road we are
%   looking for, second result is just Amsterdam
disp(results.results(1).formatted)
disp('is a')
disp(results.results(1).components.x_type)
disp(results.results(2).formatted)
disp('is a')
disp(results.results(2).components.x_type)
%   Let us say we are interested in the geo info of London, and let us
%   allow for up to the maximum number of results: 100
q='London';
[results]=OpenCageForward(key,q,'limit','100');
%   we get 50 results. Say we want to restrict our search to the UK. We set
[results]=OpenCageForward(key,q,'limit','100','countrycode','uk');
%   we get 3 results
disp(results.results(1).formatted)
disp('is a')
disp(results.results(1).components.x_type)
disp(results.results(2).formatted)
disp('is a')
disp(results.results(2).components.x_type)
disp(results.results(3).formatted)
disp('is a')
disp(results.results(3).components.x_type)


%%  Reverse search
q='0 0';
[results]=OpenCageReverse(key,'0 0');
Start your free trial

2,500 API requests per day.

No credit card required.