Use the IDX Broker API to create a Saved Link that includes polygon search coordinates.
Polygon Saved Links require latitude and longitude points that define the polygon boundary.
Important Notes
Developer Note: This example is intended for developers familiar with PHP, cURL, URL encoding, and the IDX Broker API.
Before using this example:
- Polygon coordinates are required.
- The
pgonparameter has a maximum length of 512 characters. - Simpler polygon shapes are recommended.
- Polygon lines should not intersect.
- Do not use plus signs between latitude and longitude values.
- Do not disable SSL verification in production.
- Confirm the current API version before hardcoding an
apiversionheader.
Polygon Coordinate Formatting
A polygon is created using a series of latitude and longitude coordinate pairs.
Use a space between latitude and longitude values.
Correct Format
44.69770131016885 -123.41671952046453
Incorrect Format
44.69770131016885+-123.41671952046453
Plus signs may cause encoding issues. The API may return a successful response, but the polygon overlay may not be created correctly.
Example of a Working pgon Value
44.69770131016885 -123.41671952046453,44.16225789428327 -124.16104325093329,43.56024232423529 -123.38376053608953,43.80257093351484 -122.01596268452703,44.51193134659297 -122.25766190327704,44.69770131016885 -123.41671952046453
The first and last points should match to close the polygon.
Example PHP Script
<?php
$url = 'https://api.idxbroker.com/clients/savedlinks';
$apiKey = 'YOUR_API_KEY';
$data = [
'linkName' => 'polygon_test_123456',
'pageTitle' => 'Polygon Test 123456',
'linkTitle' => 'Polygon Test 123456',
'queryString' => [
'pgon' => '44.69770131016885 -123.41671952046453,44.16225789428327 -124.16104325093329,43.56024232423529 -123.38376053608953,43.80257093351484 -122.01596268452703,44.51193134659297 -122.25766190327704,44.69770131016885 -123.41671952046453',
'radius' => '',
'layerType' => 'polygon',
'clat' => '44.135244',
'clng' => '-123.064591',
'zoom' => 9,
'idxID' => 'YOURMLS',
'pt' => 1,
'srt' => 'prd'
]
];
$encodedData = http_build_query($data);
$headers = [
'Content-Type: application/x-www-form-urlencoded',
'accesskey: ' . $apiKey,
'outputtype: json'
];
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($handle, CURLOPT_POSTFIELDS, $encodedData);
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if ($code >= 200 && $code < 300) {
$response = json_decode($response, true);
} else {
$error = $code;
}
?>
Required Values
| Field | Description |
|---|---|
linkName | Saved Link URL/name value |
pageTitle | Browser title/page title |
linkTitle | Display title for the Saved Link |
pgon | Polygon latitude/longitude points |
layerType | Should be polygon |
clat | Map center latitude |
clng | Map center longitude |
zoom | Map zoom level |
idxID | MLS ID |
pt | Property type |
srt | Sort order |
Character Limit
The pgon parameter is limited to 512 characters.
Because of this:
- Use simple polygon shapes.
- Avoid unnecessary points.
- Do not create overly detailed boundaries.
- Be careful when adding additional filters.
If the query becomes too long, the Saved Link may not function correctly.
Encoding Notes
When existing Saved Links are retrieved through the API, the polygon query string may include encoded plus signs or commas.
Examples that may fail:
44.0811730583207%2B-123.09107780456544
44.0811730583207+-123.09107780456544
Use spaces instead:
44.0811730583207 -123.09107780456544
Best Practices
- Keep polygon shapes simple.
- Do not expose API keys client-side.
- Test the Saved Link after creation.
- Confirm the polygon overlay appears correctly.
- Avoid plus signs in polygon coordinate pairs.
- Keep
pgonunder 512 characters. - Do not disable SSL verification in production.