A lightweight Go client for interacting with the Geocode.Farm API.
This SDK allows you to perform forward and reverse geocoding using the Geocode.Farm API. It has no external dependencies, making it simple and fast.
To install the Geocode.Farm Go SDK, use Go modules:
go get github.com/geocodefarm/geocodefarm-go
To convert an address into latitude and longitude:
package main
import (
"fmt"
"log"
"github.com/geocodefarm/geocodefarm-go/geocodefarm"
)
func main() {
client := geocodefarm.NewClient("YOUR_API_KEY_HERE")
resp, err := client.Forward("1600 Amphitheatre Parkway, Mountain View, CA")
if err != nil {
log.Fatalf("Error: %v", err)
}
if !resp.Success {
log.Fatalf("API Error: %s", resp.Error)
}
fmt.Println("Latitude:", *resp.Lat)
fmt.Println("Longitude:", *resp.Lon)
fmt.Println("Accuracy:", *resp.Accuracy)
fmt.Println("Full Address:", *resp.FullAddress)
}
To convert latitude and longitude into an address:
package main
import (
"fmt"
"log"
"github.com/geocodefarm/geocodefarm-go/geocodefarm"
)
func main() {
client := geocodefarm.NewClient("YOUR_API_KEY_HERE")
resp, err := client.Reverse(37.4221, -122.0841)
if err != nil {
log.Fatalf("Error: %v", err)
}
if !resp.Success {
log.Fatalf("API Error: %s", resp.Error)
}
fmt.Println("Latitude:", *resp.Lat)
fmt.Println("Longitude:", *resp.Lon)
fmt.Println("Accuracy:", *resp.Accuracy)
fmt.Println("Full Address:", *resp.FullAddress)
}
- Forward Geocoding: Converts an address (e.g.,
1600 Amphitheatre Parkway, Mountain View, CA
) into latitude and longitude. - Reverse Geocoding: Converts latitude and longitude (e.g.,
37.4221, -122.0841
) into a full address.
This repository is licensed under the Unlicense. See the LICENSE file for more information.