Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlacePicker onPlaceChange does not work as expected #221

Open
EthanChen39 opened this issue Jun 16, 2024 · 3 comments
Open

PlacePicker onPlaceChange does not work as expected #221

EthanChen39 opened this issue Jun 16, 2024 · 3 comments
Labels
type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@EthanChen39
Copy link

Environment details

  • Framework: NextJS 14
  • Language: TypeScript
  • Library Version: @googlemaps/extended-component-library": "^0.6.11

I was following the library tutorial here - link and copied the code, but it does not work as expected. For the onPlaceChange function, it does not have the "value" attribute. I am not sure how I can retrieve the formattedAddress value from the event. Any help is appreciated!
image
image

Steps to reproduce

  1. Create a next js project.
  2. Install @googlemaps/extended-component-library": "^0.6.11.
  3. Create a component with the code below

Code example

"use client";

import {
  APILoader,
  PlacePicker,
} from "@googlemaps/extended-component-library/react";

export default function MyPicker() {
  return (
    <div className="p-5">
      <APILoader
        apiKey="<YOUR-API-KEY>"
        solutionChannel="GMP_GCC_placepicker_v1"
      />
      <PlacePicker
        country={["us", "ca"]}
        location-bias="49.28273,-123.12074" // search results biased towards "Vancouver, BC"
        radius={2000}
        className="w-2/5"
        placeholder="Enter city name e.g. Vancouver, BC"
        onPlaceChange={(e) => {
          // e.target. // This line does not work as expected
        }}
      />
    </div>
  );
}

Stack trace

N.A

@EthanChen39 EthanChen39 added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 16, 2024
@leafsy
Copy link
Collaborator

leafsy commented Jun 21, 2024

Hi @EthanChen39 I'm having trouble reproducing the issue. Here's a sample nextjs project that uses the Place Picker; mind checking if this is working as expected? Note that the value property will only be defined after user selects a place result from the dropdown.

@leafsy leafsy removed the triage me I really want to be triaged. label Jun 21, 2024
@Juneezee
Copy link

@EthanChen39 Use (e.target as PlacePickerType).value

    <PlacePicker
      onPlaceChange={(e: Event): void => {
        const newPlace = (e.target as PlacePickerType).value;
        console.log(newPlace);
      }}
    />

@HMubaireek
Copy link

HMubaireek commented Sep 5, 2024

This is a working solution:

  const handlePlaceChange = (event: Event) => {
    const eventValue = (event.target as HTMLSelectElement).value;
    const place = eventValue as unknown as google.maps.places.Place;
    const latLng = place.location;
    const coordinates = { lat: latLng.lat(), lng: latLng.lng() };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants