Skip to content

Instantly share code, notes, and snippets.

@zaycker
Forked from anonymous/getCityName.js
Last active May 2, 2017 16:27
Show Gist options
  • Save zaycker/7db32cd4ab4267684982db00f741bcd4 to your computer and use it in GitHub Desktop.
Save zaycker/7db32cd4ab4267684982db00f741bcd4 to your computer and use it in GitHub Desktop.
/**
* @param {Object} locations
* @param {Number} locations.lat
* @param {Number} locations.lon
*/
export default async function (locations) {
const lat = locations.lat;
const lng = locations.lng;
const geocoder = new google.maps.Geocoder();
const latLng = new google.maps.LatLng(lat, lng);
const currentData = await new Promise(function(resolve, reject) {
geocoder.geocode(
{ latLng },
(results, status) => {
if (status === google.maps.GeocoderStatus.OK) {
resolve(results.filter(item => item.types[0] === 'administrative_area_level_1'));
} else {
reject('No results found');
}
},
);
});
console.log(currentData);
// const currentCityName = currentData[0] ? currentData[0].formatted_address : '';
// console.log(currentCityName);
return '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment