ดูรายการพื้นที่
ดึงรายการพื้นที่ (geofence) ทั้งหมดในบัญชี — พื้นที่เหล่านี้คือ โซนที่ลูกค้าวาดล้อมไว้เอง ผ่านเว็บ lite.wetrustgps.com เช่น พื้นที่คลังสินค้า จุดจอดรถ หรือเขตพื้นที่ให้บริการ
ใช้ Endpoint นี้เพื่อดึงพื้นที่ที่กำหนดไว้มาแสดงผลบนแผนที่ของระบบคุณเอง รองรับทั้งพื้นที่แบบรูปหลายเหลี่ยม (polygon) และแบบวงกลม (circle)
การยืนยันตัวตนทำผ่าน Query Parameter user_api_hash (ดู การยืนยันตัวตน)
พารามิเตอร์ (Query Parameters)
| ชื่อ | ชนิด | จำเป็น | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|---|
user_api_hash | string | ✅ | — | รหัส API ของผู้ใช้ (API Key) |
lang | string | ✅ | en | ภาษาของข้อความในผลลัพธ์ เช่น en, th |
ตัวอย่างการเรียกใช้งาน
- cURL
- JavaScript
- PHP
curl "https://lite.wetrustgps.com/api/get_geofences?lang=th&user_api_hash=YOUR_API_HASH"
const params = new URLSearchParams({
lang: 'th',
user_api_hash: 'YOUR_API_HASH',
});
const res = await fetch(
`https://lite.wetrustgps.com/api/get_geofences?${params}`,
);
const data = await res.json();
console.log(data.items.geofences);
<?php
$query = http_build_query([
'lang' => 'th',
'user_api_hash' => 'YOUR_API_HASH',
]);
$response = file_get_contents(
"https://lite.wetrustgps.com/api/get_geofences?{$query}"
);
$data = json_decode($response, true);
ทดลองยิง API
/get_geofencesทดลองยิง APIhttps://lite.wetrustgps.com/api/get_geofences?lang=thการตอบกลับ (Response)
เมื่อสำเร็จจะได้รับสถานะ 200 OK เป็นออบเจ็กต์ที่มีฟิลด์ items โดยรายการพื้นที่ทั้งหมดอยู่ในอาร์เรย์ items.geofences
ฟิลด์ของพื้นที่ (geofences[])
| ฟิลด์ | ชนิด | คำอธิบาย |
|---|---|---|
id | integer | รหัสพื้นที่ |
name | string | ชื่อพื้นที่ |
type | string | ชนิดของพื้นที่: polygon (รูปหลายเหลี่ยม) หรือ circle (วงกลม) |
active | integer | สถานะการใช้งาน (1 = เปิดใช้งาน) |
group_id | integer | รหัสกลุ่มที่พื้นที่สังกัด (0 คือ ไม่ได้จัดกลุ่ม) |
coordinates | string | null | จุดพิกัดของรูปหลายเหลี่ยมในรูปแบบสตริง JSON (ใช้เมื่อ type เป็น polygon) |
center | object | null | จุดศูนย์กลาง { lat, lng } (ใช้เมื่อ type เป็น circle) |
radius | number | null | รัศมีเป็นเมตร (ใช้เมื่อ type เป็น circle) |
polygon_color | string | สีของพื้นที่ (รหัสสี HEX) |
speed_limit | integer | ขีดจำกัดความเร็วในพื้นที่ (0 = ไม่กำหนด) |
device_id | integer | null | รหัสอุปกรณ์ที่ผูกกับพื้นที่ (ถ้ามี) |
additional | string | null | ข้อมูลเพิ่มเติม |
created_at | string | เวลาที่สร้างพื้นที่ |
updated_at | string | เวลาที่แก้ไขล่าสุด |
:::note ข้อควรทราบเรื่องรูปแบบข้อมูล
ฟิลด์ coordinates ถูกส่งมาเป็น สตริง JSON (JSON-encoded string) ของอาร์เรย์จุดพิกัด [{ "lat", "lng" }, ...] จึงต้องแปลง (parse) อีกครั้งก่อนนำไปใช้งาน
:::
ตัวอย่างการตอบกลับ
ตัวอย่างต่อไปนี้แสดงพื้นที่ทั้งสองชนิด: แบบรูปหลายเหลี่ยม (polygon) และแบบวงกลม (circle)
{
"items": {
"geofences": [
{
"id": 15221,
"user_id": 11277,
"group_id": 0,
"active": 1,
"name": "สนามบิน",
"coordinates": "[{\"lat\":13.70077940646657,\"lng\":100.75205326080324},{\"lat\":13.696443166895873,\"lng\":100.75763225555421}]",
"polygon_color": "#7d7d7d",
"type": "polygon",
"radius": null,
"center": null,
"device_id": null,
"speed_limit": 0,
"additional": null,
"created_at": "2026-08-03 08:22:50",
"updated_at": "2026-08-03 08:22:50"
},
{
"id": 15222,
"user_id": 11277,
"group_id": 0,
"active": 1,
"name": "KMITL",
"coordinates": null,
"polygon_color": "#7d7d7d",
"type": "circle",
"radius": 471.2,
"center": {
"lat": 13.72775402,
"lng": 100.77368259
},
"device_id": null,
"speed_limit": 0,
"additional": null,
"created_at": "2026-08-03 08:24:06",
"updated_at": "2026-08-03 08:24:06"
}
]
}
}
รหัสสถานะ
| สถานะ | ความหมาย |
|---|---|
200 OK | สำเร็จ คืนรายการพื้นที่ทั้งหมด |
400 Bad Request | คำขอไม่ถูกต้อง เช่น พารามิเตอร์ไม่ครบ |
401 Unauthorized | ไม่ได้แนบ user_api_hash หรือคีย์ไม่ถูกต้อง |
500 Internal Server Error | เกิดข้อผิดพลาดที่ฝั่งเซิร์ฟเวอร์ |