Örnek istek ve yanıt
Bu örnekte, Washington, DC ile New York City, NY arasındaki mesafe matrisi verileri JSON biçiminde gösterilmektedir:
URL
https://maps.googleapis.com/maps/api/distancematrix/json ?destinations=New%20York%20City%2C%20NY &origins=Washington%2C%20DC &units=imperial &key=YOUR_API_KEY
CURL
curl -L -X GET 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY'
JavaScript
var axios = require('axios'); var config = { method: 'get', url: 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY', headers: { } }; axios(config) .then(function (response) { console.log(JSON.stringify(response.data)); }) .catch(function (error) { console.log(error); });
Python
import requests url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY" payload={} headers = {} response = requests.request("GET", url, headers=headers, data=payload) print(response.text)
Java
OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = RequestBody.create(mediaType, ""); Request request = new Request.Builder() .url("https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY") .method("GET", body) .build(); Response response = client.newCall(request).execute();
Ruby
require "uri" require "net/http" url = URI("https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%2C%20DC&destinations=New%20York%20City%2C%20NY&units=imperial&key=YOUR_API_KEY") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Get.new(url) response = https.request(request) puts response.read_body
Go
package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington,%20DC&destinations=New%20York%20City,%20NY&units=imperial&key=YOUR_API_KEY" method := "GET" client := &http.Client { } req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) }
Poster
OpenAPI spesifikasyonu, bir Postman koleksiyonu olarak da mevcuttur.
Postman'de çalıştırınDeneyin. URL'yi web tarayıcınıza girerek bu isteği test edin. YOUR_API_KEY
değerini gerçek API anahtarınızla değiştirmeyi unutmayın.
Yanıt, belirtilen kaynaklar ile hedefler arasındaki mesafeyi ve süreyi gösterir.
Mevcut tüm parametreler dahil olmak üzere istek URL'lerini oluşturmayı öğrenin.
Bu kod örneği JSON ve XML biçimlerindedir:
JSON
{ "destination_addresses": ["New York, NY, USA"], "origin_addresses": ["Washington, DC, USA"], "rows": [ { "elements": [ { "distance": { "text": "228 mi", "value": 367654 }, "duration": { "text": "3 hours 55 mins", "value": 14078 }, "status": "OK", }, ], }, ], "status": "OK", }
XML
<DistanceMatrixResponse> <status>OK</status> <origin_address>Washington, DC, USA</origin_address> <destination_address>New York, NY, USA</destination_address> <row> <element> <status>OK</status> <duration> <value>14078</value> <text>3 hours 55 mins</text> </duration> <distance> <value>367654</value> <text>228 mi</text> </distance> </element> </row> </DistanceMatrixResponse>
OpenAPI spesifikasyonu
Bu API için OpenAPI spesifikasyonu yayınlanmış ve GitHub'da mevcuttur.
OpenAPI Spesifikasyonunu AlmaPostman Koleksiyonu
OpenAPI spesifikasyonu, bir Postman koleksiyonu olarak da mevcuttur.
Postman'de çalıştırYanıtı anlamak için geliştirici kılavuzunu inceleyin.