Error: The object 'details.geometry.location' is not defined and cannot be evaluated

In my app, I am utilizing the react-native-google-places-autocomplete package for two fields: Current Location and Destination. The Current Location field functions flawlessly without any errors once the location is entered and the lat/lng values are set using details.geometry.location. However, an unexpected typeError arises after setting the Destination location. Below is the relevant code snippet.

    <GooglePlacesAutocomplete
         placeholder=""
         query={{
             key: GOOGLE_PLACES_API_KEY,
             language: 'en', // language of the results
         }}
         onPress={(data, details:any) => { 
             setDestinationLatitude(details.geometry.location.lat.toString()); 
             setDestinationLongitude(details.geometry.location.lng.toString()); 
         }}
         onFail={(error) => console.error(error)}
         requestUrl={{
             url:
                'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api',
             useOnPlatform: 'web',
         }} // this in only required for use on the web. See https://git.io/JflFv more for details.
         keyboardShouldPersistTaps='always'
         styles={{
              textInputContainer: {
                  width: "90%",
                  alignSelf: 'center'
              },
              textInput: {
                  borderColor: grey,
                  borderWidth: 1,
                  borderRadius: 5,
                  height: 48,
                  paddingBottom: 8,
                  color: black,
                  fontSize: 16,
              },
              predefinedPlacesDescription: {
                  color: '#1faadb',
              },
         }}
    />

The above code snippet mirrors what I use for the Current Location field. Why then am I encountering a typeError when they are essentially identical? The only variance lies in the destinationlatitude and destinationlongitude parameters.

Answer №1

Ah, the reason has been discovered! It turns out that I simply forgot to enable the fetchDetails option. How foolish of me!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using `require` can be successful even if `qs` is not defined

I have a project running on NodeJS 14 within Google Cloud Functions. I am utilizing typescript and the tsc command to compile my code. import qs from 'qs' console.log(`qs >>> ${qs}) The output of the code snippet above (when in product ...

What is the reason behind Angular's renderer.listen() causing the text to be deselected?

(Background: my project involves developing an email processor that displays emails on a web page) To enable click events in a specific area, I leverage Angular's Renderer2. This approach is necessary because the content is dynamically generated with ...

What methods can be used to verify the compatibility of an npm package with react-native?

Is it possible to check if an npm package is compatible with react-native? I have heard that for a package to be compatible with react-native, it must have a polyfill. Is there a way to verify this? Take the package redux-persist, for example. As I cont ...

Adding styles to specific child nodes within a p-tree component in PrimeNG

Starting off with a demonstration example: Check out this StackBlitz for primeng p-tree. I am utilizing primeng to construct a structure for polls and answers using p-tree. The hierarchy is as follows: Participants --> Polls --> Questions --& ...

Removing unnecessary files from a frontend npm package in a production environment: Best practices

Having trouble organizing the build process for my frontend web app created with Angular 2 and TypeScript. This is the structure I'm working with: / - dist/ <-- transpiled .js files - src/ <-- .ts files - assets/ - bower_components/ ...

Tips for dynamically expanding the interface or type of an object in TypeScript

Currently, I am exploring the integration of PayPal's Glamorous CSS-in-JS library into a boilerplate project that also utilizes TypeScript. Glamorous provides a way to incorporate props into an element as shown below: const Section = glamorous.secti ...

What could be causing the error message "Type 'Date' is not compatible with type 'string | number'" to appear when trying to create a date using a Date object?

My function is designed to accept a date object as input and return a new date. function makeDate(date:Date) { return new Date(date); //<--error here } const newDate = new Date(); // console.log(makeDate(newDate)); // Returns date object just fine ...

Is there a way to perform type narrowing within an Angular template?

I'm facing an issue with a component that requires a business object as an Input. Within the template of this component, I need to conditionally display some content based on the presence of a property that only exists in certain subclasses of the bus ...

The element is inferred to have an 'any' type due to the fact that a 'string' type expression cannot be used to access elements in the type '{ Categories: Element; Admin: Element; }'

As someone who is new to TypeScript, I am trying to understand why I am encountering a type error in the code below (simplified): "use client"; import { ArrowDownWideNarrow, Settings } from "lucide-react"; interface LinkItemProps { ...

Design a unique React Material UI icon by combining two SVG path elements

I'm looking to customize a Material UI icon by using an SVG file with two paths, but the code I tried following in the documentation didn't give me the desired result. Since I'm still learning JavaScript and React, I thought it would be help ...

Transforming a sizeable Typescript undertaking into ES6 modules

I am faced with the challenge of transitioning a fairly large app (~650 files) that currently has a mix of ES6 modules and legacy global namespace internal modules and classes. My goal is to convert everything to 100% ES6 modules. Considering an Iterativ ...

Receiving accurate type inference and helpful editor suggestions simultaneously

How can I create a function that takes a configuration object and returns a processed version with the same keys but different values? This function should: Offer suggestions for the properties of the configuration object when calling the function. Infor ...

Creating a function that can have either one or two arguments, with the types of the arguments determined by a specific string literal

I am looking to create a function called emitEvent(event, extra?), which will be restricted by a string literal enum of known strings such as POPUP_OPEN and POPUP_CLOSED. The function will accept a second argument that is a specifically defined dictionary ...

When I apply flex to the display of .ant-steps-item-icon, the connection between the steps vanishes

I recently utilized ANTD and React to develop a customized component step style, but ran into an issue. Here is the CSS code snippet I used: /* step connector */ .ant-steps-item-title:after { border: solid rgba(65, 64, 66, 0.1) !important; } /* step * ...

What is the solution to fixing a 400 bad request error in Angular Routing?

Encountering an issue on a particular route where a 400 error is displayed in the screenshot every now and then. It seems to work fine for a few minutes after deleting cookies, but the error resurfaces after accessing it multiple times. Other routes are fu ...

Switching the language based on user preference in a React Native application

I am currently developing an app with React Native and I need the capability to change the language of the app dynamically. I have referred to a sample project at https://github.com/appfoundry/react-native-multi-language-sample as a guide. Following this, ...

What is the best way to pass a context to the function constructor?

After reading about the dangers of using the eval method, I decided to utilize a function constructor to prevent any malicious code injection. Here is the approach I took: function evalContext(context: Record<string, unknown>) { const injectCon ...

What is the method to have VIM recognize backticks as quotes?

Currently working in TypeScript, I am hoping to utilize commands such as ciq for modifying the inner content of a template literal. However, it appears that the q component of the command only recognizes single and double quotation marks as acceptable ch ...

Typescript: Defining the correct return type for resolved parameters in promises

Exploring the world of TypeScript, I recently attempted to convert some basic JavaScript promise samples into TypeScript promises. While working on this conversion process, I encountered an issue that has left me puzzled and unable to find a solution even ...

Utilize a segment of typography to craft a brand new design

Recently, I created a type known as TranslationsData: [key: string]: { translation: { state: AnotherType } }; Now, I am looking to incorporate this section: [key: string]: { translation: { state: into another type, with the only modification being the An ...