**Experimental** plus codes API

73 views
Skip to first unread message

Doug Rinckes

unread,
Dec 9, 2016, 8:52:39 AM12/9/16
to open-location-code EXTERNAL
I've implemented a web-based, JSON API to convert from locations to plus codes and back. I'm announcing it here in the hopes some of you will try it out and let me know what you think.

The parameters and returned JSON object are both closely based on the Google Geocoding API format.

To encode a location, make a request with the latitude and longitude:

This will return a JSON object:
{
  "results": [
    {
      "plus_code": {
        "global_code": "796RWF8Q+WF",
        "code_area": {
          "northeast": {
            "lat": 14.917375000000007,
            "lng": -23.511250000000018
          },
          "southwest": {
            "lat": 14.91725000000001,
            "lng": -23.511375000000015
          }
        }
      }
    }
  ],
  "status": "OK"
}

If you have a code and you want to decode it, make a request with the code (you must correctly escape the "+" sign):

The result will be the same as the encode result, with the full code and the coordinates of the bounding box.

If you have a shortened code, and need to recover the original global code relative to a location (say, the user's current position), use:

This will find the nearest WF8Q+WF to the passed lat/lng and decode it, returning the same JSON object as above.

If you want to convert the code_area bounding box to a single lat/lng, say to mark it on a map or something, compute the center like this:

var lat = (data.results[0].plus_code.code_area.northeast.lat +
           data.results[0].plus_code.code_area.southwest.lat) / 2;
var lng = (data.results[0].plus_code.code_area.northeast.lng +
           data.results[0].plus_code.code_area.southwest.lng) / 2;

If you have a Google Geocoding API key, you can include it in your request (with the key= parameter). The results will be the same that you would normally get from the geocoding API, but each result will also have the plus code information added to it. In the interests of keeping this email short, I'm not going to go into a lot of detail, so play with it and send me your impression or questions!

Finally - I need your feedback! Is this useful? Should the JSON object be formatted differently, are there fields missing or extra fields you don't need? Is anything confusing? Let me know!

Doug Rinckes
Technical Program Manager
Google Switzerland

charles...@gmail.com

unread,
Dec 9, 2016, 9:01:33 AM12/9/16
to open-location-code
Quite handful.

Tony B

unread,
Dec 10, 2016, 2:26:30 AM12/10/16
to open-location-code
Tremendous!
Reply all
Reply to author
Forward
0 new messages