Coder Social home page Coder Social logo

here-go's Introduction

HERE Go

PkgGoDev GoReportCard Codecov

Go SDK for the HERE Maps API.

Documentation

API documentation can be found at developer.here.com.

Installing

$ go get go.einride.tech/here

Authentication

The package does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you.

Note that when using an authenticated Client, all calls made by the client will include the same authentication data. Therefore, authenticated clients should almost never be shared between different users.

Complete Examples

v7 Routing API

Route calculation

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"

	"go.einride.tech/here/routingv7"
)

func main() {
	ctx := context.Background()
	apiKey := os.Getenv("HERE_API_KEY")
	// Create an authenticated client
	routingClient := routingv7.New(
		routingv7.NewAPIKeyHTTPClient(apiKey, http.DefaultClient.Transport),
	)
	// Einride Gothenburg.
	origin := &routingv7.GeoWaypoint{
		Lat:  57.707752,
		Long: 11.949767,
	}
	// Einride Stockholm.
	destination := &routingv7.GeoWaypoint{
		Lat:  59.337492,
		Long: 18.063672,
	}
	// Call Here Maps API
	response, err := routingClient.Route.CalculateRoute(ctx, &routingv7.CalculateRouteRequest{
		Waypoints: []routingv7.WaypointParameter{origin, destination},
		Mode: routingv7.RoutingMode{
			Type: routingv7.RouteTypeFastest,
		},
	})
	if err != nil {
		panic(err) // TODO: Handle error.
	}
	// Handle result
	for _, route := range response.Routes {
		fmt.Println(route.Summary)
	}
}

v8 Routing API

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"

	"go.einride.tech/here/routingv8"
)

func main() {
	ctx := context.Background()
	apiKey := os.Getenv("HERE_API_KEY")
	// Create an authenticated client
	routingClient := routingv8.New(
		routingv8.NewAPIKeyHTTPClient(apiKey, http.DefaultClient.Transport),
	)
	// Einride Gothenburg.
	origins := []*routingv8.GeoWaypoint{
		{
			Lat:  57.707752,
			Long: 11.949767,
		},
	}
	// Einride Stockholm.
	destinations := []*routingv8.GeoWaypoint{
		{
			Lat:  59.337492,
			Long: 18.063672,
		},
	}
	// Call Here Maps API
	response, err := routingClient.Matrix.CalculateMatrix(ctx, &routingv8.CalculateMatrixRequest{
		Async: false,
		Body: &routingv8.CalculateMatrixBody{
			Origins:      origins,
			Destinations: destinations,
			RegionDefinition: routingv8.RegionDefinition{
				Type: routingv8.RegionType_World,
			},
			Profile: routingv8.Profile_TruckFast,
			MatrixAttributes: &routingv8.MatrixAttributes{
				routingv8.MatrixAttribute_Distances,
				routingv8.MatrixAttribute_TravelTimes,
			},
		},
	})
	if err != nil {
		panic(err) // TODO: handle error
	}
	// Handle result
	fmt.Printf("matrix ID: %s \n", response.MatrixID)
	for i, distance := range response.Matrix.Distances {
		fmt.Printf("Route %d: %d meters \n", i, distance)
	}
}

here-go's People

Contributors

alethenorio avatar asperine avatar dependabot[bot] avatar ericwenn avatar jsegura avatar odsod avatar oliviaeinride avatar pmarkus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.