|
@@ -3,13 +3,18 @@
|
|
|
const GEOCODER = new google.maps.Geocoder();
|
|
|
|
|
|
export const reverseGeocode = async location => {
|
|
|
- const { results } = await GEOCODER.geocode({ location });
|
|
|
- for (const { address_components } of results) {
|
|
|
- for (const { short_name, types } of address_components) {
|
|
|
- if (types.indexOf("country") >= 0) {
|
|
|
- return short_name;
|
|
|
+ try {
|
|
|
+ const { results } = await GEOCODER.geocode({ location });
|
|
|
+ for (const { address_components } of results) {
|
|
|
+ for (const { short_name, types } of address_components) {
|
|
|
+ if (types.indexOf("country") >= 0) {
|
|
|
+ return short_name;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } catch (e) {
|
|
|
+ // ignore errors - just use null
|
|
|
+ // TODO probably alert the user?
|
|
|
}
|
|
|
return null;
|
|
|
};
|