Newer Version Available
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
1Map<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.
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
1// Create a list of geographical IDs and set the shape merging parameter.
2List<String> geoIds = new List<String>{'CAN-5-24360123', 'CAN-5-24360125'};
3Boolean mergeShape = false;
4
5// Call the GetBoundaryGeoJSON() method with the geographical IDs and shape merging parameter.
6Map<String, Object> response = maps.API.GetBoundaryGeoJSON(geoIds, mergeShape);
7
8// Log the resulting boundary.
9system.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.
1{
2 "total": {
3 "perimeter": 76052.889956049, // Total length in meters of all boundary perimeters.
4 "area": 92743880.3549741 // Total area in square meters inside of all boundaries.
5 },
6 "unit": "meters",
7 "geometries": {
8 "CAN-5-24360125": {
9 "perimeter": 64556.086852368, // Length in meters of the boundary perimeter.
10 "area": 88393467.4191344 // Area in square meters inside the boundary.
11 },
12 "CAN-5-24360123": {
13 "perimeter": 11496.803103681,
14 "area": 4350412.93583968
15 }
16 },
17 "count": 2,
18 "custom": false
19}