The getPolygonGeometry() Apex method returns the geometric data, such as the area and perimeter, for the requested geographical shape or custom polygon.
maps is the namespace that’s available after you install Salesforce Maps.
API is the class that contains the global methods exposed to developers.
getPolygonGeometry() is the method.
Sample Code of a Circle
This code passes a circular geographical region to the Salesforce Maps API.
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
Uncommitted work errors can also arise if calling out to Salesforce Maps methods more than one time in a single transaction and the Salesforce Maps token hasn’t refreshed in the last 24 hours. If these errors occur, separate each callout into individual transactions.
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 a Circle
1{2 type: 'circle', // Shape.3 radius: Decimal, // Radius in meters from the center of the polygon.4 lat: Decimal, // Latitude coordinate of the center of the circle.5 lng: Decimal // Longitude coordinate of the center of the circle.6}
Example
1// Create a circular geographical region.2Map<String,Object>polygon = new Map<String,Object>{3 'type' =>'circle',4 'radius' =>50,5 'lat' =>33.917760,6 'lng' => -84.3797507};89// Call the getPolygonGeometry() method with the new polygon.10Map<String,Object>response = maps.API.getPolygonGeometry(polygon);1112// Log the information about the resulting polygon.13system.debug(response);
Sample Code of a Rectangle
This code passes a rectangular geographical region to the Salesforce Maps API.
Input Format of a Rectangle
1{2 type: 'rectangle', // Shape.3 NE: Map<String,Decimal>, // North-Eastern corner of the rectangle.4 SW: Map<String,Decimal> // South-Western corner of the rectangle.5}
Example
1// Add the geographical coordinates of the North-Eastern and South-Western corners.2Map<String,Decimal>northEast = new Map<String,Decimal>{3 'lat' =>33.943360,4 'lng' => -84.5155415};67Map<String,Decimal>southWest = new Map<String,Decimal>{8 'lat' =>33.559707,9 'lng' => -84.10192910};1112// Create the rectangular geographical region.13Map<String,Object>polygon = new Map<String,Object>{14 'type' =>'rectangle',15 'NE' =>northEast,16 'SW' =>southWest17};1819// Call the getPolygonGeometry() method with the new polygon.20Map<String,Object>response = maps.API.getPolygonGeometry(polygon);2122// Log the information about the resulting polygon.23system.debug(response);
Sample Code of a Polygon
This code passes a polygonal geographical region to the Salesforce Maps API.
Input Format of a Polygon
1{2 type: 'polygon', // Shape.3 points: List<Map<String,Decimal>> // List of latitude and longitude coordinates of the polygon corners.4}
Example
1// Create an array with the geographical coordinates of the corners of the polygon.2String pointsArray = '[{"lat":34.29494470071453,"lng":-83.86492811369591},{"lat":34.167779992443144,"lng":-85.15032850432091},{"lat":32.80256665568334,"lng":-84.63397108244591},{"lat":33.32736906742004,"lng":-82.72234998869591}]';34// Create the polygonal geographical region.5Map<String,Object>polygon = new Map<String,Object>{6 'type' =>'polygon',7 'points'=>JSON.deserializeUntyped(pointsArray)8};910// Call the getPolygonGeometry() method with the new polygon.11Map<String,Object>response = maps.API.getPolygonGeometry(polygon);1213// Log the information about the resulting polygon.14system.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.