Should I convert this google geocode method to an observable?
If so, how would I do it?
FYI - I don't think I need to reject the promise, just return a null, so I made that little change below.
const geoCode = new Geocode();
geoCode.geocode('some address').then(place => {
console.log(place.geometry.location);
})
.catch(err => {
console.log(err);
});
export class Geocode {
geocode(address: string): Promise<any> {
const geocoder = new google.maps.Geocoder();
return new Promise((resolve, reject) => {
geocoder.geocode({
address: address
},
(results, status) => {
if (status === google.maps.GeocoderStatus.OK) {
resolve(results[0]);
} else {
// reject(new Error(status)); // don't need to reject
resolve(null);
}
}
);
});
}
}