⬆️ ⬇️

Introduction to what3words API: Basic Procedures and Samples





Our main task was to give addresses to every place on the planet, and today this task is completed. What3words squares grid covers the entire globe, and each square has a unique address. It's time to give everyone the opportunity to use the addresses of three words, and make it convenient. It will be convenient when each map, navigation application and other geolocation services will support what3words. For this, our API was created, about which we want to tell in detail.



We tried to make the interface as simple as possible, and made every effort to save the time and nerves of the developers. The interface performs two basic procedures: converting 3 words to a location, and converting a location to 3 words. The third additional procedure is a request for a list of three-word available languages. In most cases, all communication with the API comes down to simple GET requests. Responses are provided in JSON.



1. Convert 3 words to location



')

The procedure turns 3 words into a latitude / longitude coordinate pair. The what3words addresses are given in squares measuring 3 x 3 meters, and the resulting coordinates are the coordinates of the center of such a square. Together with the coordinates, the response contains the requested three words, to which all corrections are applied.



Extra options



For this procedure, an additional language parameter (lang) is provided, which will change the language of the returned 3 words in accordance with the specified parameter. Since the API is able to automatically recognize the language of the sent words, the parameter is useful only if you want to receive in the response an address in another language other than the one used in the request.



If you want to receive in the answer the coordinates of the corners of the square, you can use the corresponding additional parameter (corners = true). Together with the coordinates of the center of the square in the answer, you get the coordinates of its southeast and northwest corners.



When building your interface, it may be helpful to know the lengths of the elements. The length of each word in what3words is from 3 to 18 characters, and the vast majority of words describing objects on land are 4 to 12 characters long. Thus, the address length of 3 words ranges from 14 (3x4 letters + 2 dots) to 38 (3x12 letters + 2 dots) characters.



URL

 http://api.what3words.com/w3w


GET Required Parameters

keyyour API key
stringword 1. word 2. word 3


Advanced GET options

langadditional language code
corners“True” or “false”


Answer



  {
	 "type": "3 words",
	 "words": ["prom", "cape", "pump"],
	 "position": [51.484463, -0.195405],
	 "language": "en"
 } 




Code samples



GET example
  http://api.what3words.com/w3w?key=YOURAPIKEY&lang=en&string=index.home.raft 




Php
  <? php

 $ ch = curl_init ('http://api.what3words.com/w3w');

 $ fields = array (
		 'key' => 'YOURAPIKEY',
		 'string' => 'prom.cape.pump'
 );

 curl_setopt ($ ch, CURLOPT_POST, count ($ fields));
 curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ fields));
 curl_setopt ($ ch, CURLOPT_HEADER, false);
 curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true);

 $ return = curl_exec ($ ch);
 $ return = json_decode ($ return, true);

 curl_close ($ ch); 




Linux curl
  curl --data "key = YOURAPIKEY & string = prom.cape.pump" http://api.what3words.com/w3w 




Jquery
  data = {
	 'key': 'YOURAPIKEY',
	 'string': 'prom.cape.pump'
 };

 $ .post ('http://api.what3words.com/w3w', data, function (response) {
	 console.log (response);
 }); 






Regular expressions

  /^\pILL++\.ILL++\.plL++$/u 




2. Convert location to 3 words





Each set of latitude / longitude coordinates falls into one of the squares of the what3words global grid and has a corresponding address of 3 words. Coordinates describing a location within a single square have the same address. This procedure returns the coordinates of the center of the square and its address of 3 words.



The optional language parameter (lang) can be used to select a language in which you will receive an address of 3 words. By default, the interface uses addresses in English. You can also query the coordinates of the corners of the square with the parameter (corners = true). As in the first procedure, the answer will contain the coordinates of the southwest and northeast corners of the square.



URL

  http://api.what3words.com/position 


GET Parameters

key (required)your API key
position (required)lat, lng (in degrees)
langadditional language code
corners“True” or “false”


Answer

  {
	 "words": ["prom", "cape", "pump"],
	 "position": [51.484463, -0.195405],
	 "language": "en"
 } 


Code samples



GET example
  http://api.what3words.com/position?key=YOURAPIKEY&lang=en&position=51.521251 ,-0.203586 




Php
  <? php

 $ ch = curl_init ('http://api.what3words.com/position');

 $ fields = array (
		 'key' => 'YOURAPIKEY',
		 'position' => '51 .484463, -0.195405 '
 );

 curl_setopt ($ ch, CURLOPT_POST, count ($ fields));
 curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ fields));
 curl_setopt ($ ch, CURLOPT_HEADER, false);
 curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true);

 $ return = curl_exec ($ ch);
 $ return = json_decode ($ return, true);

 curl_close ($ ch); 




Linux curl
  curl --data "key = YOURAPIKEY & position = 51.484463, -0.195405" http://api.what3words.com/position 




Jquery
  data = {
	 'key': 'YOURAPIKEY',
	 'position': '51 .484463, -0.195405 '
 };

 $ .post ('http://api.what3words.com/position', data, function (response) {
	 console.log (response);
 }); 






3. Getting a list of available what3words address languages





URL

  http://api.what3words.com/get-languages 


GET Required Parameters

keyyour API key


Answer

  {
	 "languages": {
					 {"code": "en",
					   "name": "English"},
					 {..}
	 }
 } 


Code samples



GET example
  http://api.what3words.com/get-languages?key=YOURAPIKEY&lang=en&position=51.521251 ,-0.203586

 http://api.what3words.com/get-langauges?key=YOURAPIKEY&lang=en&strong=index.home.raft 




Php
  <? php

 $ ch = curl_init ('http://api.what3words.com/get-languages');

 $ fields = array (
		 'key' => 'YOURAPIKEY'
 );

 curl_setopt ($ ch, CURLOPT_POST, count ($ fields));
 curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ fields));
 curl_setopt ($ ch, CURLOPT_HEADER, false);
 curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true);

 $ return = curl_exec ($ ch);
 $ return = json_decode ($ return, true);

 curl_close ($ ch); 




Linux curl
  curl --data "key = YOURAPIKEY & position = 51.484463, -0.195405" http://api.what3words.com/position 




Jquery
  data = {
	 'key': 'YOURAPIKEY',
	 'position': '51 .484463, -0.195405 '
 };

 $ .post ('http://api.what3words.com/position', data, function (response) {
	 console.log (response);
 }); 






You can get acquainted with the API now. Sign up at this link , indicating at the very bottom that you are registering to receive a key to the API. Later we will tell you in detail about our libraries, SDK and other tools for developers.

Source: https://habr.com/ru/post/253319/



All Articles