0

Localization

by
Published Apr 8, 2025

Foxentry allows you to check an area with GPS radius in order to return all the addresses within that area. It can also give you additional information about the addresses based on the dataScope option.Please pay attention to the singleLocationResultDistance option, which determines the radius of the search area in meters.

Script foxentry Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Foxentry = {
3
  apiKey: string;
4
};
5
/**
6
 * Localization
7
 * Foxentry allows you to check an area with GPS radius in order to return all the addresses within that area. It can also give you additional information about the addresses based on the dataScope option.Please pay attention to the singleLocationResultDistance option, which determines the radius of the search area in meters.
8
 */
9
export async function main(
10
  auth: Foxentry,
11
  api_version: string | undefined,
12
  foxentry_include_request_details: string | undefined,
13
  body: {
14
    request: {
15
      customId?: string;
16
      query: { lat: number; lon: number };
17
      options?: {
18
        dataScope?: "basic" | "full";
19
        dataSource?: string[];
20
        zipFormat?: false | true;
21
        countryFormat?:
22
          | "alpha2"
23
          | "alpha3"
24
          | "local"
25
          | "localShortened"
26
          | "international"
27
          | "internationalShortened";
28
        cityFormat?: "basic" | "minimal" | "extended";
29
      } & { radius?: number; acceptNearest?: false | true };
30
      client?: { ip?: string; country?: string };
31
    };
32
  },
33
) {
34
  const url = new URL(`https://api.foxentry.com/location/localize`);
35

36
  const headers: Record<string, string> = {
37
    "Content-Type": "application/json",
38
    Authorization: "Bearer " + auth.apiKey,
39
  };
40

41
  if (api_version) {
42
    headers["api-version"] = api_version;
43
  }
44
  if (foxentry_include_request_details) {
45
    headers["foxentry-include-request-details"] = foxentry_include_request_details;
46
  }
47

48
  const response = await fetch(url, {
49
    method: "POST",
50
    headers,
51
    body: JSON.stringify(body),
52
  });
53
  if (!response.ok) {
54
    const text = await response.text();
55
    throw new Error(`${response.status} ${text}`);
56
  }
57
  return await response.json();
58
}
59