Retrieve the Geographical Data of Country-Specific Shapes

The GetBoundaryGeoJSON() Apex method returns the geographical data, area, and perimeter for a list of geographical IDs.

Signature

Map<String, Object> maps.API.GetBoundaryGeoJSON(List<String> geoIds, Boolean mergeShape)
Where,
  • maps is the namespace that's available after you install Salesforce Maps.
  • API is the class that contains the global methods exposed to developers.
  • GetBoundaryGeoJSON() is the method.

Sample Code

This code takes two geographical IDs and returns their total and individual geometric data, area, and perimeter.

If you invoke methods within a flow, process builder, or trigger, avoid uncommitted work errors when you perform one of the following.

  • Call the methods through a future method
  • Call the methods as queueable

Different processes refresh the token, such as plotting a route or schedule. The refresh process is almost immediate after each qualifying action occurs.

Warning

Input Format of the Parameters

  • A list of geographical IDs with the format {countrycode}-{level}-{id}.
  • A Boolean that determines whether the returned information of the shape is merged (true) or separated (false).

Example

// Create a list of geographical IDs and set the shape merging parameter.
List<String> geoIds = new List<String>{'CAN-5-24360123', 'CAN-5-24360125'};
Boolean mergeShape = false;

// Call the GetBoundaryGeoJSON() method with the geographical IDs and shape merging parameter.
Map<String, Object> response = maps.API.GetBoundaryGeoJSON(geoIds, mergeShape);

// Log the resulting boundary.
system.debug(response);

Sample Response

Although the return value is an Apex Map<String, Object> object, this JSON response illustrates the essential data you receive in the resulting map.

{
  "total": {
    "perimeter": 76052.889956049, // Total length in meters of all boundary perimeters.
    "area": 92743880.3549741 // Total area in square meters inside of all boundaries.
  },
  "unit": "meters",
  "geometries": {
    "CAN-5-24360125": {
      "perimeter": 64556.086852368, // Length in meters of the boundary perimeter.
      "area": 88393467.4191344 // Area in square meters inside the boundary.
    },
    "CAN-5-24360123": {
      "perimeter": 11496.803103681,
      "area": 4350412.93583968
    }
  },
  "count": 2,
  "custom": false
}