示例#1
0
func TestGeocodeFullAddressReturningTimezone(t *testing.T) {
	Geocodio, err := geocodio.NewGeocodio(APIKey())
	if err != nil {
		t.Error("Failed with API KEY set.", err)
	}
	result, err := Geocodio.GeocodeAndReturnTimezone(AddressTestOneFull)
	if err != nil {
		t.Error(err)
	}

	t.Log(result.Debug)

	if len(result.Results) == 0 {
		t.Error("Results length is 0")
	}

	if result.Results[0].Location.Latitude != 33.739464 {
		t.Error("Location latitude does not match", result.Results[0].Location.Latitude, 33.739464)
	}

	if result.Results[0].Location.Longitude != -116.40803 {
		t.Error("Location longitude does not match", result.Results[0].Location.Longitude, -116.40803)
	}

	if result.Results[0].Fields.Timezone.Name == "" {
		t.Error("Timezone field not found")
	}

	if !result.Results[0].Fields.Timezone.ObservesDST {
		t.Error("Timezone field does not match", result.Results[0].Fields.Timezone)
	}
}
示例#2
0
func TestReverseGeocodeFullAddress(t *testing.T) {
	Geocodio, err := geocodio.NewGeocodio(APIKey())

	if err != nil {
		t.Error("Failed with API KEY set.", APIKey(), err)
	}

	result, err := Geocodio.ReverseGeocode(AddressTestTwoLatitude, AddressTestTwoLongitude)
	if err != nil {
		t.Error(err)
	}

	t.Log(result.Debug)

	if len(result.Results) == 0 {
		t.Error("Results length is 0")
	}

	if len(result.Results) < 3 {
		t.Error("Results found length is less than 3", len(result.Results))
	}

	if result.Results[0].Location.Latitude != 38.900203 {
		t.Error("Location latitude does not match", result.Results[0].Location.Latitude, 38.900203)
	}

	// if result.Results[0].Location.Longitude != ​-76.999507 {
	//    t.Error("Location longitude does not match", result.Results[0].Location.Longitude, ​"-76.999507")
	//  }
}
示例#3
0
func main() {

	Geocodio, err := geocodio.NewGeocodio("YOUR_API_KEY")
	if err != nil {
		panic(err)
	}

	result, err := Geocodio.Geocode("42370 Bob Hope Dr, Rancho Mirage, CA")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Geocode Result %v", result)

	resultReverse, err := Geocodio.ReverseGeocode(38.9002898, -76.9990361)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Reverse Geocode Result %v", resultReverse)
}
示例#4
0
func TestGeocodeFullAddressReturningMultipleFields(t *testing.T) {
	Geocodio, err := geocodio.NewGeocodio(APIKey())
	if err != nil {
		t.Error("Failed with API KEY set.", err)
	}
	result, err := Geocodio.GeocodeReturnFields(AddressTestOneFull, "timezone", "cd")
	if err != nil {
		t.Error(err)
	}

	t.Log(result.Debug)

	if len(result.Results) == 0 {
		t.Error("Results length is 0")
	}

	if result.Results[0].Location.Latitude != 33.739464 {
		t.Error("Location latitude does not match", result.Results[0].Location.Latitude, 33.739464)
	}

	if result.Results[0].Location.Longitude != -116.40803 {
		t.Error("Location longitude does not match", result.Results[0].Location.Longitude, -116.40803)
	}

	if result.Results[0].Fields.Timezone.Name == "" {
		t.Error("Timezone field not found")
	}

	if !result.Results[0].Fields.Timezone.ObservesDST {
		t.Error("Timezone field does not match", result.Results[0].Fields.Timezone)
	}

	// check congressional district
	if result.Results[0].Fields.CongressionalDistrict.Name == "" {
		t.Error("Congressional District field not found", result.Results[0].Fields.CongressionalDistrict)
	}

	if result.Results[0].Fields.CongressionalDistrict.DistrictNumber != 36 {
		t.Error("Congressional District field does not match", result.Results[0].Fields.CongressionalDistrict)
	}

}
示例#5
0
func TestGeocodeFullAddressReturningStateLegislativeDistricts(t *testing.T) {
	Geocodio, err := geocodio.NewGeocodio(APIKey())
	if err != nil {
		t.Error("Failed with API KEY set.", err)
		t.Fail()
	}

	result, err := Geocodio.GeocodeAndReturnStateLegislativeDistricts(AddressTestOneFull)
	if err != nil {
		t.Error(err)
	}

	t.Log(result.Debug)

	if len(result.Results) == 0 {
		t.Error("Results length is 0", result)
		t.Fail()
	}

	if result.Results[0].Location.Latitude != 33.739464 {
		t.Error("Location latitude does not match", result.Results[0].Location.Latitude, 33.739464)
		t.Fail()
	}

	if result.Results[0].Location.Longitude != -116.40803 {
		t.Error("Location longitude does not match", result.Results[0].Location.Longitude, -116.40803)
		t.Fail()
	}

	if result.Results[0].Fields.StateLegislativeDistricts.House.DistrictNumber != "42" {
		t.Error("State Legislative Districts house does not match", result.Results[0].Fields.StateLegislativeDistricts.House)
		t.Fail()
	}

	if result.Results[0].Fields.StateLegislativeDistricts.Senate.DistrictNumber != "28" {
		t.Error("State Legislative Districts senate does not match", result.Results[0].Fields.StateLegislativeDistricts.Senate)
		t.Fail()
	}
}
示例#6
0
func TestGeocodeFullAddressReturningCongressionalDistrict(t *testing.T) {
	Geocodio, err := geocodio.NewGeocodio(APIKey())
	if err != nil {
		t.Error("Failed with API KEY set.", err)
		t.Fail()
	}
	result, err := Geocodio.GeocodeAndReturnCongressionalDistrict(AddressTestOneFull)
	if err != nil {
		t.Error(err)
	}

	t.Log(result.Debug)

	if len(result.Results) == 0 {
		t.Error("Results length is 0")
		t.Fail()
	}

	if result.Results[0].Location.Latitude != 33.739464 {
		t.Error("Location latitude does not match", result.Results[0].Location.Latitude, 33.739464)
		t.Fail()
	}

	if result.Results[0].Location.Longitude != -116.40803 {
		t.Error("Location longitude does not match", result.Results[0].Location.Longitude, -116.40803)
		t.Fail()
	}

	if result.Results[0].Fields.CongressionalDistrict.Name == "" {
		t.Error("Congressional District field not found", result.Results[0].Fields.CongressionalDistrict)
		t.Fail()
	}

	if result.Results[0].Fields.CongressionalDistrict.DistrictNumber != 36 {
		t.Error("Congressional District field does not match", result.Results[0].Fields.CongressionalDistrict)
		t.Fail()
	}
}
示例#7
0
func TestGeocodeFullAddress(t *testing.T) {
	Geocodio, err := geocodio.NewGeocodio(APIKey())
	if err != nil {
		t.Error("Failed with API KEY set.", err)
	}
	result, err := Geocodio.Geocode(AddressTestOneFull)
	if err != nil {
		t.Error(err)
	}

	t.Log(result.Debug)

	if len(result.Results) == 0 {
		t.Error("Results length is 0")
	}

	if result.Results[0].Location.Latitude != 33.739464 {
		t.Error("Location latitude does not match", result.Results[0].Location.Latitude, 33.739464)
	}

	if result.Results[0].Location.Longitude != -116.40803 {
		t.Error("Location longitude does not match", result.Results[0].Location.Longitude, -116.40803)
	}
}
示例#8
0
func TestGeocodioWithoutApiKey(t *testing.T) {
	_, err := geocodio.NewGeocodio("")
	if err == nil {
		t.Error("Did not through error when omitting API KEY")
	}
}
示例#9
0
func TestGeocodioWithApiKey(t *testing.T) {
	_, err := geocodio.NewGeocodio(APIKey())
	if err != nil {
		t.Error("Failed with API KEY set.", err)
	}
}