Geocoding API v4 มีความสามารถหลัก 2 กลุ่ม ได้แก่ การค้นหาจุดหมายสำหรับแอตทริบิวต์เจาะจงเฉพาะพื้นที่ที่สมบูรณ์ และการเข้ารหัสพิกัดภูมิศาสตร์พื้นฐาน (การแปลงพิกัดเป็นที่อยู่) หากไม่แน่ใจว่าควรใช้วิธีใด ดูเลือกวิธีการเข้ารหัสพิกัดภูมิศาสตร์
- ค้นหาจุดหมาย (
SearchDestinations): ดึงข้อมูลรายละเอียดการมาถึงที่สมบูรณ์สำหรับจุดหมาย ซึ่งรวมถึงทางเข้าอาคาร จุดนำทางที่กำหนดเส้นทางได้ เค้าโครงอาคาร/พื้นที่ จุดหมายย่อย และจุดสังเกตใกล้เคียง - การเข้ารหัสพิกัดภูมิศาสตร์ (
GeocodeAddress): แปลงที่อยู่เป็นพิกัดละติจูดและลองจิจูดเพื่อวางเครื่องหมายพื้นฐานหรือจัดแผนที่ให้อยู่กึ่งกลาง - การเข้ารหัสพิกัดภูมิศาสตร์แบบย้อนกลับ (
GeocodeLocation): แปลงพิกัดทางภูมิศาสตร์เป็นที่อยู่ซึ่งมนุษย์อ่านได้ - การเข้ารหัสพิกัดภูมิศาสตร์ของสถานที่ (
GeocodePlace): ค้นหาที่อยู่ที่จัดรูปแบบแล้วและพิกัดสำหรับรหัสสถานที่ที่ทราบ
ตัวอย่างคำขอและการตอบกลับ
คุณเข้าถึง Geocoding API ผ่านอินเทอร์เฟซ HTTP ด้านล่างนี้คือตัวอย่างการเริ่มต้นใช้งานด่วนสำหรับการค้นหาจุดหมาย การเข้ารหัสที่อยู่เป็นพิกัดภูมิศาสตร์ และการเข้ารหัสพิกัดภูมิศาสตร์แบบย้อนกลับ
คำขอและการตอบกลับการค้นหาจุดหมาย (ข้อมูลการมาถึงแบบเจาะจงเฉพาะพื้นที่)
ตัวอย่างต่อไปนี้จะส่งคำขอ HTTP POST ไปยัง SearchDestinations สำหรับ "1600 Amphitheatre Parkway, Mountain View, CA" โปรดทราบว่า SearchDestinations ต้องมีส่วนหัว X-Goog-FieldMask ที่ระบุช่องที่จะแสดงผล ดังนี้
curl -X POST -d '{ "addressQuery": { "addressQuery": "1600 Amphitheatre Parkway, Mountain View, CA" } }' \ -H 'Content-Type: application/json' \ -H 'X-Goog-FieldMask: destinations.primary.displayName,destinations.primary.formattedAddress,destinations.primary.location,destinations.primary.displayPolygon,destinations.entrances,destinations.navigationPoints,destinations.landmarks' \ -H "X-Goog-Api-Key: YOUR_API_KEY" \ "https://geocode.googleapis.com/v4/geocode/destinations"
ด้านล่างนี้คือตัวอย่างการตอบกลับของ SearchDestinations ที่แสดงรูปหลายเหลี่ยมของรอยเท้าอาคาร ทางเข้าที่ต้องการ จุดนำทางที่กำหนดเส้นทางได้ และสถานที่สำคัญในบริเวณใกล้เคียง
{ "destinations": [ { "primary": { "displayName": { "text": "Googleplex", "languageCode": "en" }, "formattedAddress": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", "location": { "latitude": 37.4220656, "longitude": -122.0840897 }, "displayPolygon": { "type": "Polygon", "coordinates": [ [ [-122.084958, 37.422145], [-122.084112, 37.422610], [-122.083510, 37.421980], [-122.084958, 37.422145] ] ] } }, "entrances": [ { "location": { "latitude": 37.422189, "longitude": -122.084215 }, "tags": ["PREFERRED"] } ], "navigationPoints": [ { "navigationPointToken": "Eg...", "displayName": { "text": "Amphitheatre Pkwy Dropoff", "languageCode": "en" }, "location": { "latitude": 37.421912, "longitude": -122.084301 }, "travelModes": ["DRIVE"], "usages": ["DROPOFF", "PICKUP"] } ], "landmarks": [ { "place": { "displayName": { "text": "Charleston Park", "languageCode": "en" } }, "relationalDescription": { "text": "Adjacent to Charleston Park", "languageCode": "en" }, "straightLineDistanceMeters": 85.4 } ] } ] }
คำขอและการตอบกลับการเข้ารหัสพิกัดภูมิศาสตร์ (การค้นหาละติจูด/ลองจิจูด)
ตัวอย่างต่อไปนี้จะขอละติจูดและลองจิจูดของ "1600 Amphitheatre Parkway, Mountain View, CA" และระบุว่าเอาต์พุตต้องอยู่ในรูปแบบ JSON
curl -H "X-Goog-Api-Key: YOUR_API_KEY" \ "https://geocode.googleapis.com/v4/geocode/address/1600+Amphitheatre+Parkway,+Mountain+View,+CA"
คุณทดสอบได้โดยป้อน URL ลงในเว็บเบราว์เซอร์ (อย่าลืมแทนที่ YOUR_API_KEY ด้วยคีย์ API จริง)
การตอบกลับจะมีละติจูดและลองจิจูดของที่อยู่
ดูคู่มือสำหรับนักพัฒนาซอฟต์แวร์เพื่อดูข้อมูลเพิ่มเติมเกี่ยวกับ การสร้าง URL คำขอการเข้ารหัสพิกัดภูมิศาสตร์, พารามิเตอร์ที่ใช้ได้ และ การทำความเข้าใจการตอบกลับ
ด้านล่างนี้คือตัวอย่างการตอบกลับการเข้ารหัสพิกัดภูมิศาสตร์ในรูปแบบ JSON
{ "results": [ { "place": "//places.googleapis.com/places/ChIJ2Z2idB66j4ARI43TG-9RoCQ", "placeId": "ChIJ2Z2idB66j4ARI43TG-9RoCQ", "location": { "latitude": 37.4438238, "longitude": -122.0869895 }, "granularity": "ROOFTOP", "viewport": { "low": { "latitude": 37.4424748197085, "longitude": -122.0883384802915 }, "high": { "latitude": 37.445172780291493, "longitude": -122.08564051970852 } }, "formattedAddress": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", "postalAddress": { "regionCode": "US", "languageCode": "en", "postalCode": "94043-1351", "administrativeArea": "CA", "locality": "Mountain View", "addressLines": [ "1600 Amphitheatre Pkwy" ] }, "addressComponents": [ { "longText": "1600", "shortText": "1600", "types": [ "street_number" ] }, { "longText": "Amphitheatre Parkway", "shortText": "Amphitheatre Pkwy", "types": [ "route" ], "languageCode": "en" }, { "longText": "Mountain View", "shortText": "Mountain View", "types": [ "locality", "political" ], "languageCode": "en" }, { "longText": "Santa Clara County", "shortText": "Santa Clara County", "types": [ "administrative_area_level_2", "political" ], "languageCode": "en" }, { "longText": "California", "shortText": "CA", "types": [ "administrative_area_level_1", "political" ], "languageCode": "en" }, { "longText": "United States", "shortText": "US", "types": [ "country", "political" ], "languageCode": "en" }, { "longText": "94043", "shortText": "94043", "types": [ "postal_code" ] }, { "longText": "1351", "shortText": "1351", "types": [ "postal_code_suffix" ] } ], "types": [ "premise", "street_address" ] } ] }
คำขอและการตอบกลับการเข้ารหัสพิกัดภูมิศาสตร์แบบย้อนกลับ (การค้นหาที่อยู่)
ตัวอย่างต่อไปนี้ขอที่อยู่ที่สอดคล้องกับละติจูด/ลองจิจูดที่ระบุในบรูคลิน นิวยอร์ก สหรัฐอเมริกา ซึ่งระบุว่าเอาต์พุตต้องอยู่ในรูปแบบ JSON
https://geocode.googleapis.com/v4/geocode/location/37.4225508,-122.0846338?key=YOUR_API_KEYคุณทดสอบได้โดยป้อน URL ลงในเว็บเบราว์เซอร์ (อย่าลืมแทนที่ "YOUR_API_KEY" ด้วยคีย์ API จริง) การตอบกลับจะมีที่อยู่ที่มนุษย์อ่านได้สำหรับตำแหน่งละติจูดและลองจิจูด
ดูข้อมูลเพิ่มเติมเกี่ยวกับ การสร้าง URL คำขอการเข้ารหัสพิกัดภูมิศาสตร์แบบย้อนกลับ, พารามิเตอร์ที่ใช้ได้ และ การทำความเข้าใจการตอบกลับได้ในคู่มือนักพัฒนาซอฟต์แวร์
ด้านล่างนี้คือตัวอย่างการตอบกลับการเข้ารหัสพิกัดภูมิศาสตร์แบบย้อนกลับในรูปแบบ JSON
{ "results": [ { "place": "//places.googleapis.com/places/ChIJHRNUiQK6j4ARJ__Hrbt6qsE", "placeId": "ChIJHRNUiQK6j4ARJ__Hrbt6qsE", "location": { "latitude": 37.4225657, "longitude": -122.08465439999999 }, "granularity": "ROOFTOP", "viewport": { "low": { "latitude": 37.421214719708509, "longitude": -122.08603273029148 }, "high": { "latitude": 37.423912680291508, "longitude": -122.0833347697085 } }, "bounds": { "low": { "latitude": 37.4225178, "longitude": -122.08484599999998 }, "high": { "latitude": 37.422609600000008, "longitude": -122.0845215 } }, "formattedAddress": "Google Building 40, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", "postalAddress": { "regionCode": "US", "languageCode": "en", "postalCode": "94043", "administrativeArea": "CA", "locality": "Mountain View", "addressLines": [ "Google Building 40", "1600 Amphitheatre Pkwy" ] }, "addressComponents": [ { "longText": "Google Building 40", "shortText": "Google Building 40", "types": [ "premise" ], "languageCode": "en" }, { "longText": "1600", "shortText": "1600", "types": [ "street_number" ] }, { "longText": "Amphitheatre Parkway", "shortText": "Amphitheatre Pkwy", "types": [ "route" ], "languageCode": "en" }, { "longText": "Mountain View", "shortText": "Mountain View", "types": [ "locality", "political" ], "languageCode": "en" }, { "longText": "Santa Clara County", "shortText": "Santa Clara County", "types": [ "administrative_area_level_2", "political" ], "languageCode": "en" }, { "longText": "California", "shortText": "CA", "types": [ "administrative_area_level_1", "political" ], "languageCode": "en" }, { "longText": "United States", "shortText": "US", "types": [ "country", "political" ], "languageCode": "en" }, { "longText": "94043", "shortText": "94043", "types": [ "postal_code" ] } ], "types": [ "street_address", "subpremise" ] }, ... Additional results truncated in this example[] ... }
การตรวจสอบสิทธิ์ โควต้า ราคา และนโยบาย
การตรวจสอบสิทธิ์
หากต้องการใช้ Geocoding API คุณต้องเปิดใช้ API ก่อน และรับข้อมูลรับรองการตรวจสอบสิทธิ์ที่เหมาะสม ดูข้อมูลเพิ่มเติมได้ที่หัวข้อเริ่มต้นใช้งาน Google Maps Platform
โควต้าและการกำหนดราคา
ดูรายละเอียดเกี่ยวกับโควต้าและราคาที่กำหนดไว้สำหรับ Geocoding API ได้ที่หน้าการใช้งานและการเรียกเก็บเงิน
นโยบาย
การใช้ Geocoding API ต้องเป็นไปตามนโยบาย API