From 7932631c20710ef22da555d3832ef9ef34fa32cf Mon Sep 17 00:00:00 2001 From: Kseniia Maiesh Date: Thu, 28 Aug 2025 16:18:22 +0300 Subject: [PATCH 1/2] FE-63 --- examples/Google Directions.md | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/Google Directions.md diff --git a/examples/Google Directions.md b/examples/Google Directions.md new file mode 100644 index 0000000..0cacf3d --- /dev/null +++ b/examples/Google Directions.md @@ -0,0 +1,42 @@ +# Google Directions With Go + +Returns directions between two points from Google Maps.[Outscraper API](https://app.outscraper.cloud/api-docs#tag/Google/paths/~1maps~1directions/get). + +## Installation + +Go 1.10+ must be already installed. + +Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is): +``` sh +go mod init +``` + +``` go +go get -u github.com/outscraper/outscraper-go +``` + +[Link to the Go module page](https://pkg.go.dev/github.com/outscraper/outscraper-go) + +## Initialization +```go +package main + +import ( + "fmt" + "github.com/outscraper/outscraper-go" +) + +client := outscraper.Client{ApiKey: "SECRET_API_KEY"} +``` +[Link to the profile page to create the API key](https://app.outscraper.com/profile) + +## Usage + +```go +# Returns directions: +results, _ := client.GoogleMapsDirections(map[string]string { + "origin": "[\"29.696596,76.994928\",\"30.715966244353,76.8053887016268\"]", + "destination": "[\"29.696596,76.994928\",\"30.723065,76.770169\"]", +}) +fmt.Println(results) +``` From 9cafbb9ceb8f51b86ce650ec5f23d386e416035e Mon Sep 17 00:00:00 2001 From: Kseniia Maiesh Date: Fri, 29 Aug 2025 12:21:50 +0300 Subject: [PATCH 2/2] query updated --- examples/Google Directions.md | 14 ++++++++++---- outscraper.go | 20 +++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/Google Directions.md b/examples/Google Directions.md index 0cacf3d..7fdf17a 100644 --- a/examples/Google Directions.md +++ b/examples/Google Directions.md @@ -34,9 +34,15 @@ client := outscraper.Client{ApiKey: "SECRET_API_KEY"} ```go # Returns directions: -results, _ := client.GoogleMapsDirections(map[string]string { - "origin": "[\"29.696596,76.994928\",\"30.715966244353,76.8053887016268\"]", - "destination": "[\"29.696596,76.994928\",\"30.723065,76.770169\"]", -}) +results, _ := client.GoogleMapsDirections(map[string]interface{}{ + "origin": [][]string{ + {"29.696596", "76.994928"}, + {"30.715966244353", "76.8053887016268"}, + }, + "destination": [][]string{ + {"29.696596", "76.994928"}, + {"30.723065", "76.770169"}, + }, + }) fmt.Println(results) ``` diff --git a/outscraper.go b/outscraper.go index dbe58e6..40639e7 100644 --- a/outscraper.go +++ b/outscraper.go @@ -87,9 +87,23 @@ func (c Client) GoogleMapsSearchV3(parameters map[string]string) ([]interface{}, return response["data"].([]interface{}), err } -func (c Client) GoogleMapsDirections(parameters map[string]string) ([]interface{}, error) { - parameters["async"] = "false" - response, err := c.getAPIRequest("/maps/directions", parameters) +func (c Client) GoogleMapsDirections(parameters map[string]interface{}) ([]interface{}, error) { + q := url.Values{} + + for key, val := range parameters { + switch v := val.(type) { + case []string: + for _, item := range v { + q.Add(key, item) + } + case string: + q.Add(key, v) + } + } + + q.Set("async", "false") + + response, err := c.getAPIRequest("/maps/directions", q) return response["data"].([]interface{}), err }