mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 04:24:56 -06:00
33 lines
776 B
JavaScript
33 lines
776 B
JavaScript
// @flow
|
|
import { GoogleAPIKey } from "../constants/AppConstants";
|
|
import { path } from "ramda";
|
|
|
|
const url = "https://maps.googleapis.com/maps/api/geocode/json";
|
|
|
|
type Location = {
|
|
lat: number,
|
|
lng: number
|
|
};
|
|
|
|
type AddressComponent = {
|
|
long_name: string,
|
|
short_name: string,
|
|
types: Array<string>
|
|
};
|
|
|
|
type GeocodeResult = {
|
|
results: Array<{
|
|
address_components: Array<AddressComponent>,
|
|
formatted_address: string,
|
|
geometry: {
|
|
location: Location
|
|
},
|
|
place_id: string,
|
|
types: Array<string>
|
|
}>
|
|
};
|
|
|
|
export const getCoordsFromZip = async (zip: string): Promise<Location> => {
|
|
const res: GeocodeResult = await (await fetch(`${url}?key=${GoogleAPIKey}&address=${zip}`)).json();
|
|
return path(["results", 0, "geometry", "location"], res) || { lat: 0, lng: 0 };
|
|
};
|