Saturday, March 9, 2024
HomeiOS Developmentios - React Native - Google Reverse Geocoding Does not Work in...

ios – React Native – Google Reverse Geocoding Does not Work in Manufacturing


I’m utilizing Google’s geocoding API to get lat/lng from an deal with.

This works when I’m operating the app in Expo, however once I compile for iOS, the request fails.

That is actually arduous to debug as I’ve to rebuild the app and undergo TestFlight each change I make. It really works once I run expo run:ios and run the dev construct within the simulator.

This is my code

    const fetchCoordinates = async () => {
      attempt {

        const apiKey = Util.getPlatformAPIKey();
        const googleApiUrl = `https://maps.googleapis.com/maps/api/geocode/json?deal with=${encodeURIComponent(deal with)}&key=${apiKey}`;

        const response = await fetch(googleApiUrl, {
          mode: "no-cors",
          redirect: "observe",
          methodology: "GET",
        });

        if (!response.okay) {
          return;
        } else {
          setStatus("Response from geocoding API okay");
        }

        const information = await response.json();

        if (information.outcomes.size > 0) {
          const {lat, lng} = information.outcomes[0].geometry.location;
          return {latitude: lat, longitude: lng};
        } else {
          return undefined;
        }
      } catch (error) {
        console.error("Error fetching coordinates:", error);
      }
    };

Appears to only return undefined. Google Cloud Console will not be displaying any errors.

Is iOS blocking requests to googleapis.com? I’ve NSAllowsArbitraryLoads set to true

"NSAppTransportSecurity": {
    "NSAllowsArbitraryLoads": true
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments