jaing / react-native-places-input

MIT License
46 stars 18 forks source link

Bug when clicking on predictions #3

Closed Jeca1801 closed 4 years ago

Jeca1801 commented 4 years ago

Sometimes when i click on a prediction i get an TypeError: undefined is not an object (evaluating 'place.result.formmated_adress') error.. and sometimes it works good

https://gyazo.com/f8603e6ed6f903cd97a548374c59fbfe

jaing commented 4 years ago

Can you replicate this query using API directly and post a response here? I will need to validate it and see what API is returning. I.e.

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=110%20Ward&location=40.7128%2C-74.0059&radius=500&types=address&components=country%3ACA%7Ccountry%3AUS&key=YOUR_API_KEY

Jeca1801 commented 4 years ago

response.txt

jaing commented 4 years ago

Any which one is causing a trouble?

Jeca1801 commented 4 years ago

hm i'm unsure on getting the response that i want... I'm from sweden.. and my search input is stockholm.. my latitude 59.30403924658636 and longitude 18.048340380191807. could you help me out? could you fill in these in the proper location and i'll fix the api key..

jaing commented 4 years ago

So in a response there is an array of places. My question is which one is causing an API error when you click it.

Jeca1801 commented 4 years ago

when i click on a option in the predictions it says undefined is not an object ... and its pointing to place.result.formatted_adress... sometimes it happens to every one of the predictions and sometimes it doesent happend and it works fine... does this answer your question?

jaing commented 4 years ago

I need a place id to debug it. You send me a response with multiple places:

{ "predictions" : [ { "description" : "110 Ward Drive, New Rochelle, New York, USA", "id" : "3ed4273818378bfea2b2a2ee7b5261a4403533d2", "matched_substrings" : [ { "length" : 3, "offset" : 0 }, { "length" : 4, "offset" : 4 } ], "place_id" : "ChIJzT6wM7OTwokR95iWmndXFP0", "reference" : "ChIJzT6wM7OTwokR95iWmndXFP0", "structured_formatting" : { "main_text" : "110 Ward Drive", "main_text_matched_substrings" : [ { "length" : 3, "offset" : 0 }, { "length" : 4, "offset" : 4 } ], "secondary_text" : "New Rochelle, New York, USA" }, "terms" : [ { "offset" : 0, "value" : "110" }, { "offset" : 4, "value" : "Ward Drive" }, { "offset" : 16, "value" : "New Rochelle" }, { "offset" : 30, "value" : "New York" }, { "offset" : 40, "value" : "USA" } ], "types" : [ "premise", "geocode" ] }, ]

I need a place_id that is causing this error. I.e. when i click "110 Ward Drive, New Rochelle, New York, USA i get an error. Or when i click on Staten Island, New York, USA.

Also please post your implementation - i.e.

<PlacesInput language="en" />

Jeca1801 commented 4 years ago

https://gyazo.com/1d8015302dcd01e6dc91efba79a76499 so this is my implementations (i cut out the api key) .. this is the response i get back when using the api in my code {"html_attributions": [], "result": {"formatted_address": "Uppsala, Sweden", "geometry": {"location": [Object], "viewport": [Object]}, "name": "Uppsala"}, "status": "OK"}... how do i provide the place_id, sir?

jaing commented 4 years ago

can you try 1.0.9 version?

Jeca1801 commented 4 years ago

tried it seemed to work better but i still get this error sometimes... https://gyazo.com/278eab82fb642fd2d0e8d4f8a122bfee

Jeca1801 commented 4 years ago

it's weird because it works alot of the times for the same one..

jaing commented 4 years ago

Yes it is weird. If you change your onSelect method to console.log(place) not setState and see if it works? Looks like a problem is on your end since i added a safe check in a new version:

place && place.result && (place.result.formatted_address || place.result.name),

Jeca1801 commented 4 years ago

i still get the same error even if i log it

jaing commented 4 years ago

Sorry but this is technically impossible. There is only one palce in a code in current version where I'm referring to a formatted_address and there is a safe check for that (place && place.result && (place.result.formatted_address || place.result.name),). Maybe you can clear you node modules and reinstall a package.