Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)

This application provide a REST API for mapcodes.
Available methods:
This application provides a REST API for mapcodes. It uses the Java Library for Mapcodes
extensively.

The available REST API methods are:

GET /mapcode Returns this help page.
GET /mapcode/version Returns the software version.
Expand All @@ -15,30 +17,35 @@ Available methods:

Convert latitude/longitude to one or more mapcodes.
Path parameters:
lat : latitude, range [-90, 90]
lon : longitude, range [-180, 180] (mapped if outside range)
lat : Latitude, range [-90, 90] (automatically limited to this range).
lon : Longitude, range [-180, 180] (automatically wrapped to this range).

An additional filter can be specified to limit the results:
all : same as without specifying a filter, returns all mapcodes
local : return the shortest local mapcode
international : return the shortest international mapcode
all : Same as without specifying a filter, returns all mapcodes.
local : Return the shortest local mapcode.
international : Return the international mapcode.

Query parameters:
precision : precision, range [0, 2] (default=0)
territory : territory to restrict results to, numeric or alpha code
alphabet : Alphabet to return results in, numeric or alpha code
precision : Precision, range [0, 2] (default=0).
territory : Territory to restrict results to, numeric or alpha code.
alphabet : Alphabet to return results in, numeric or alpha code.

include : Multiple options may be set, separated by comma's:
offset = include offset from mapcode center to lat/lon (in meters)
territory = always include territory in result, also for territory 'AAA'
alphabet = always include mapcodeInAlphabet, even if the same as mapcode
offset = Include offset from mapcode center to lat/lon (in meters).
territory = Always include territory in result, also for territory 'AAA'.
alphabet = Always the mapcodeInAlphabet, also if same as mapcode.

GET /mapcode/coords/{code} [?territory={mapcodeTerritory}]
Convert a mapcode into a latitude/longitude pair
Note that you can use 'include=territory,alphabet' to ensure the territory code
is always present, as well as the translated territory and mapcode codes.
This can make processing the records easier in scripts, for example.

GET /mapcode/coords/{code} [?context={territoryContext}]
Convert a mapcode into a latitude/longitude pair.

Path parameters:
code : mapcode code (local or international)
code : Mapcode code (local or international).
Query parameters:
territory : mapcode territory, numeric or alpha code
context : Optional mapcode territory context, numeric or alpha code.

GET /mapcode/territories [?offset={offset}&count={count}]
Return a list of all territories.
Expand All @@ -47,10 +54,10 @@ Available methods:
Return information for a single territory code.

Path parameters:
territory : territory to get info for, numeric or alpha code
territory : Territory to get info for, numeric or alpha code.

Query parameters:
territoryContext: territory context (optional, for disambiguation)
context : Territory context (optional, for disambiguation).

GET /mapcode/alphabets [?offset={offset}&count={count}]
Return a list of all alphabet codes.
Expand All @@ -59,13 +66,13 @@ Available methods:
Return information for a specific alphabet.

Path parameters:
alphabet : alphabet to get info for, numeric or alpha code
alphabet : Alphabet to get info for, numeric or alpha code.

General query parameters for methods which return a list of results:

offset : return list from 'offset' (negative value start counting from end)
count : return 'count' items at most

offset : Return list from 'offset' (negative value start counting from end).
count : Return 'count' items at most.

## Building The REST API Service

Expand All @@ -81,14 +88,17 @@ If you wish to use MongoDB tracing, will need to provide your own local
in `src/main/resources` which override the following properties:

MongoDBTrace.writeEnabled = true
MongoDBTrace.servers = your-server:27017
MongoDBTrace.database = your-database
MongoDBTrace.servers = your-server:27017 (eg. localhost:27017)
MongoDBTrace.database = your-database (eg. trace)
MongoDBTrace.userName = your-username
MongoDBTrace.password = your-password

The service will work without this, but will not trace events to the
database.


## Using Java 8 on MacOSX

The source uses Java JDK 1.8, so make sure your Java compiler is set to 1.8, for example
using something like (MacOSX):

Expand Down
2 changes: 2 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ <h2>REST API Version</h2>
var alphabet = document.getElementById("alphabetEncode").value;
var lat = document.getElementById("lat").value;
var lon = document.getElementById("lon").value;

/* Add include=territory,alphabet to make sure the territory and alphabet values are always present. */
var url = apiBaseURL + "/codes/" + lat + "," + lon + "?include=territory,alphabet" +
((territory && (territory.length != 0)) ? "&territory=" + territory : "") +
((precision && (precision.length != 0)) ? "&precision=" + precision : "") +
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<artifactId>mapcode-rest-service</artifactId>

<packaging>war</packaging>
<version>1.50.1.3</version>
<version>1.50.2.0</version>

<name>Mapcode REST API Web Service</name>
<description>
Expand Down Expand Up @@ -87,7 +87,7 @@
<resteasy.version>3.0.11.Final</resteasy.version>
<slf4j.version>1.7.2</slf4j.version>

<mapcode.version>1.50.1</mapcode.version>
<mapcode.version>1.50.2</mapcode.version>
<speedtools.version>3.0.9</speedtools.version>

<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import akka.dispatch.Futures;
import com.google.common.base.Joiner;
import com.mapcode.*;
import com.mapcode.Territory.NameFormat;
import com.mapcode.Territory.AlphaFormat;
import com.mapcode.services.ApiConstants;
import com.mapcode.services.MapcodeResource;
import com.mapcode.services.SystemMetricsCollector;
Expand Down Expand Up @@ -72,8 +72,8 @@ public class MapcodeResourceImpl implements MapcodeResource {
final Territory parentTerritory = x.getParentTerritory();
return new TerritoryDTO(
x.toString(),
x.toNameFormat(NameFormat.MINIMAL_UNAMBIGUOUS),
x.toNameFormat(NameFormat.MINIMAL),
x.toAlpha(AlphaFormat.MINIMAL_UNAMBIGUOUS),
x.toAlpha(AlphaFormat.MINIMAL),
x.getCode(),
x.getFullName(),
(parentTerritory == null) ? null : parentTerritory.toString(),
Expand Down Expand Up @@ -403,8 +403,8 @@ public void getTerritory(
final Territory parentTerritory = territory.getParentTerritory();
final TerritoryDTO result = new TerritoryDTO(
territory.toString(),
territory.toNameFormat(NameFormat.MINIMAL_UNAMBIGUOUS),
territory.toNameFormat(NameFormat.MINIMAL),
territory.toAlpha(AlphaFormat.MINIMAL_UNAMBIGUOUS),
territory.toAlpha(AlphaFormat.MINIMAL),
territory.getCode(),
territory.getFullName(),
(parentTerritory == null) ? null : parentTerritory.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class RootResourceImpl implements RootResource {
" Convert latitude/longitude to one or more mapcodes.\n" +

" Path parameters:\n" +
" lat : Latitude, range [-90, 90].\n" +
" lon : Longitude, range [-180, 180] (mapped if outside range).\n\n" +
" lat : Latitude, range [-90, 90] (automatically limited to this range).\n" +
" lon : Longitude, range [-180, 180] (automatically wrapped to this range).\n\n" +

" An additional filter can be specified to limit the results:\n" +
" all : Same as without specifying a filter, returns all mapcodes.\n" +
Expand All @@ -64,12 +64,17 @@ public class RootResourceImpl implements RootResource {
" Query parameters:\n" +
" precision : Precision, range [0, 2] (default=0).\n" +
" territory : Territory to restrict results to, numeric or alpha code.\n" +
" alphabet : Alphabet to return results in, numeric or alpha code.\n" +
" alphabet : Alphabet to return results in, numeric or alpha code.\n\n" +

" include : Multiple options may be set, separated by comma's:\n" +
" offset = Include offset from mapcode center to lat/lon (in meters).\n" +
" territory = Always include territory in result, also for territory 'AAA'.\n" +
" alphabet = Always the mapcodeInAlphabet, also if same as mapcode.\n\n" +

" Note that you can use 'include=territory,alphabet' to ensure the territory code\n" +
" is always present, as well as the translated territory and mapcode codes.\n" +
" This can make processing the records easier in scripts, for example.\n\n" +

"GET /mapcode/coords/{code} [?context={territoryContext}]\n" +
" Convert a mapcode into a latitude/longitude pair.\n\n" +

Expand Down