-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f32e0df
commit b18cf13
Showing
15 changed files
with
133 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package google | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1" | ||
"googlemaps.github.io/maps" | ||
) | ||
|
||
var errNoResults = errors.New("no results found for coordinates") | ||
|
||
func ReverseGeocode(ctx context.Context, c *maps.Client, location *v1beta1.LatLng) ([]maps.GeocodingResult, error) { | ||
results, err := c.ReverseGeocode(ctx, &maps.GeocodingRequest{ | ||
LatLng: &maps.LatLng{ | ||
Lat: location.GetLatitude(), | ||
Lng: location.GetLongitude(), | ||
}, | ||
ResultType: nil, | ||
LocationType: nil, | ||
PlaceID: "", | ||
Language: "", | ||
Custom: nil, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(results) == 0 { | ||
return nil, errNoResults | ||
} | ||
return results, err | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Package osrm provides functions over the Open Source Routing Machine project. | ||
We use OSRM's Table service when we want to quickly determine the duration | ||
and/or distance between two points (without traffic awareness). This could be | ||
useful for saving money/requests to Google Maps API every time an anonymous end | ||
user sees an estimate quote for a potential trip. | ||
https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#table-service | ||
We use OpenStreetMap's /reverse endpoint for reverse geocoding. | ||
https://nominatim.org/release-docs/develop/api/Reverse/ | ||
*/ | ||
package osrm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package osrm | ||
|
||
import ( | ||
"fmt" | ||
"github.com/codingsince1985/geo-golang" | ||
"github.com/codingsince1985/geo-golang/openstreetmap" | ||
"github.com/kr/pretty" | ||
) | ||
|
||
const ( | ||
addr = "Melbourne VIC" | ||
lat, lng = -37.813611, 144.963056 | ||
) | ||
|
||
func ReverseGeocode() { | ||
try(openstreetmap.Geocoder()) | ||
} | ||
|
||
func try(geocoder geo.Geocoder) { | ||
location, _ := geocoder.Geocode(addr) | ||
if location != nil { | ||
fmt.Printf("%s location is (%.6f, %.6f)\n", addr, location.Lat, location.Lng) | ||
} else { | ||
fmt.Println("got <nil> location") | ||
} | ||
address, _ := geocoder.ReverseGeocode(lat, lng) | ||
if address != nil { | ||
fmt.Printf("Address of (%.6f,%.6f) is %s\n", lat, lng, address.FormattedAddress) | ||
pretty.Println(address) | ||
} else { | ||
fmt.Println("got <nil> address") | ||
} | ||
fmt.Print("\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package osrm | ||
|
||
import "testing" | ||
|
||
func TestReverseGeocode(t *testing.T) { | ||
ReverseGeocode() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters