Simple Google Maps Web Service API Wrapper on Go Google Maps Web Service API
$ go get github.com/pamungkaski/malkist-go
- Distance Matrix API link
- Elevation API link
- Geolocation API link
- Time Zone API link
- Directions API link
- Roads API link
- Geocoding link
- Place API for Web link
You'll need Google API key to use malkist, so checkout get api key
package main
import (
"github.com/pamungkaski/malkist-go"
"fmt"
)
func main() {
m := malkist.Malkist{
Key: "YOUR API KEY",
}
// to changeAPI key
m.ChangeAPIKey("YOUR API KEY")
}
Main Function :
// distance.go
func (m Malkist) CalculateDistance(origins, destinations []string) ([]DistanceMatrix, error)
Return Struct :
// distance.go
package malkist
// DistanceMatrix represent the value that returned from CalculateDistance.
type DistanceMatrix struct {
Origin string `json:"origin"`
Destination string `json:"destination"`
Distance float64 `json:"distance"`
Duration float64 `json:"duration"`
}
CalculateDistance
will return array of DistanceMatrix even when it is only between two coordinate.
Calculate distance between two coordinate :
package main
import (
"github.com/pamungkaski/malkist-go"
"fmt"
)
func main() {
m := malkist.Malkist{}
distance, err := m.CalculateDistance([]string{"40.6655101, -73.89188969999998"}, []string{"40.6905615, -73.9976592",})
if err != nil {
fmt.Errorf(err.Error())
}
fmt.Println(distance)
}
Calculate distance between multiple coordinate :
package main
import (
"github.com/pamungkaski/malkist-go"
"fmt"
)
func main() {
m := malkist.Malkist{}
distance, err := m.CalculateDistance(
[]string{"40.6655101, -73.89188969999998", "40.6905615, -73.9976592",},
[]string{"40.6905615, -73.9976592", "40.6655101, -73.89188969999998",},
)
if err != nil {
fmt.Errorf(err.Error())
}
fmt.Println(distance)
}
After checking out the repo, run
$ dep ensure
To install the dependencies of this library
Run:
$ go test -v
Bug reports and pull requests are welcome on GitHub at https://github.com/pamungkaski/malkist-go. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Malkist project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.