I'm trying to call Google Geocoding API in React Native
app, using javascript fetch
method.
The problem is that I'm receiving weird response, like:
{"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "0049b5e6-4602-439c-b371-ca885e1e45c0", "offset": 0, ... }
Note: the url is healthy, when I copy & paste it in browser address bar, it returns correct response.
Here's my method:
export const getAddress = async (lat, lng) => {
const url = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${GOOGLE_API_KEY}`;
const response = await fetch(url);
// response.ok is true
if (!response.ok) {
throw new Error('Failed to fetch address!');
}
const data = response.json();
console.log('RESPONSE', response); // Outputs: {"_bodyBlob": {"_data": {"__collector": [Object], "blobId": "0049b5e6-4602-439c-b371-ca885e1e45c0", "offset": 0, ... }
console.log('DATA', data); // Outputs: DATA {"_A": null, "_x": 0, "_y": 0, "_z": null}
const address = data.results[0].formatted_address; // throws error
return address;
};
Any ideas?