Discovering the latitude and longitude coordinates of an address through react-google-places-autocomplete

I'm currently integrating the react-google-places-autocomplete package into my project and I require the latitude and longitude from an address. Despite following their documentation, I keep encountering the error message:

"This API project is not authorized to use this API. For more information on authentication and Google Maps JavaScript API services"

Even after enabling Geocoding and GeoLocating APIs, I am still facing the same issue. Below is a snippet of my code:

import GooglePlacesAutocomplete, { geocodeByAddress, getLatLng } from 'react-google-places-autocomplete';

const handleAddress = (e) => {
    setSelectedAddress(e);
    geocodeByAddress('Montevideo, Uruguay')
   .then(results => getLatLng(results[0]))
  .then(({ lat, lng }) =>
    console.log('Successfully retrieved latitude and longitude', { lat, lng })
  );

<GooglePlacesAutocomplete
   apiKey={config.url.Google_key}
   selectProps={{
   placeholder: 'Address *',
   name: "address",
   inputValue: inputField['address'],
   onInputChange: (e) => {setInputField({...inputField, ['address']: e})},
   onChange: (place) => {handleAddress(place.label); setErrorAddress(false);console.log(place)}
   }}
/>

For testing purposes, I am using a static address at the moment. Please advise on what could be going wrong in my implementation.

Answer №1

selectedLocation={place =>
    {
        console.log('Latitude:', place.geometry.location.lat())
        console.log('Longitude:', place.geometry.location.lng())
    }
}

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

Rendering on the server with a focus on the header

Can server side rendering be limited to only <head></head> data? I am exploring options similar to next.js: export async function getServerSideProps(context) { return { props: {}, // will be passed to the page component as props } } Ba ...

Implement a call feature using ReactJS

My service method involves making a PUT call to an API with an ID parameter. However, I am facing issues with hitting the .put URL. Can someone please verify if this is the correct approach? ENDPOINTS = { SAMPLE: "/sample", }; Below is my ...

What is the best way to save an array of objects from an Axios response into a React State using TypeScript?

Apologies in advance, as I am working on a professional project and cannot provide specific details. Therefore, I need to describe the situation without revealing actual terms. I am making a GET request to an API that responds in the following format: [0: ...

ReactJS: The issue of input values getting overridden in an array

Users can input their names and numbers, which are then displayed in a list. I am currently working on adding these numbers to an array to prevent duplicates. Although I have the numbers saved in a variable, I am facing the issue of only one number being ...

JSX: dynamically include element based on condition

I am currently utilizing Bootstrap 3 and I have a requirement to clear each .row once 12 columns have been generated. However, my code is not working as expected and I encounter this error: Failed to compile. Error in ./src/File/file.js Syntax error: Unex ...

Having trouble changing the chosen selection in the material UI dropdown menu

I've encountered an issue with my material ui code for a select dropdown. It seems that the selected option is not updating properly within the dropdown. <FormControl variant="outlined" className={classes.formControl}> <InputLabel ref={ ...

Updating input value in controlled component in React using Redux upon button click

I have a controlled input field in my form that I want to update via button click. Despite updating the state and changing the value, the input's inner HTML remains the same. What could be causing this issue? Could it be because my form state is store ...

Using React form input event handler effectively

I have integrated an API to fetch country codes and store them in a select field as options. The user can select a country from the dropdown menu, and the corresponding calling code will automatically appear in an input box. My goal is to make sure that w ...

Leveraging React Router with the withRouter functionality

Is it possible to access the routing context, location, params, etc., using withRouter() in React? import { withRouter } from 'react-router'; const SomeComponent = ({location, route, params}) => ( <h1>The current location is {locat ...

Error message: The module cannot be found by the compiler. This issue is resolved when using Visual Code and Definitely

As a newcomer to Typescript, I'm encountering an issue that I believe might have a simple solution. After installing type definitions for a JavaScript library, the compiler is throwing an error that has me stumped. Working on a React Typescript projec ...

Leveraging data within Gatsby to dynamically generate and display content

I am encountering a problem as a newcomer to Gatsby. In my EventsContainer, I have an UpcomingEvent component where I need to render specific data only when upcomingEvent is true. While I successfully utilized map for EventCard, I'm struggling to do t ...

JavaScript Class experiencing issues with returning NAN when using the Multiplication method

Currently, I have a JavaScript Class with a multiplication method that aims to multiply all elements of an array excluding those that are undefined. To achieve this, I utilized a for loop to check the data type of each element (ensuring it is a number) and ...

Encountering an error in my next.js application during Server Side Render page build, where I am unable to read properties of null, specifically 'useReducer'

I recently developed a Next.js application where I implemented user authentication using React context and reducer. Here's the code for my context: import React from "react"; import { createContext, useContext, useReducer } from "react& ...

Seeking clarification on how the Typescript/Javascript and MobX code operates

The code provided below was utilized in order to generate an array consisting of object groups grouped by date. While I grasped the overall purpose of the code, I struggled with understanding its functionality. This particular code snippet is sourced from ...

Learn how to efficiently apply styles to multiple objects within an array using the material-ui library

Currently, I'm utilizing the functional component of React.js. Within this component, I have an array of objects that contain specific styles. const data = [ { id: 1, color: '#000' }, { ...

What is the process for crafting a Vuejs controlled input form?

Although I am familiar with creating controlled components in React using state, I am new to the Vue framework and would like to understand how to adapt my code from React to be compatible with Vue. My goal is to store the values of input fields in a data ...

"Enhance user experience with Material UI's versatile layout component designed for seamless transition between desktop

I am designing a responsive Single Web App using material ui, but I'm unsure about whether to use a grid or a box for the main component placement. Here is a visual representation of how the main components are arranged in different screen sizes: md, ...

Trouble with React.js variables not showing up in CSS when using Tailwind CSS

import React from "react"; import carousel from "../assets/index"; import Image from "next/image"; const threeD = () => { const length = carousel.length; const cardWidth = 288; const cardsGap = 4; const cir ...

Retrieving theme variables from a prior session in createMuiTheme

Utilizing Material UI version 1.0.0-beta.24 I am currently implementing a new theme using the method createMuiTheme: import {createMuiTheme} from 'material-ui/styles'; const theme = createMuiTheme({ typography: { fontSize: 16 } }); ex ...

Personalized renderInput within the material-ui autocomplete

Is there a way to display my Account component in both renderInput and renderOptions? I need it to show up in both scenarios. demo.js /* eslint-disable no-use-before-define */ import React from "react"; import Autocomplete from "@material-u ...