Shrutimahajan / Google-AutoComplete-TextField-Flutter

MIT License
28 stars 98 forks source link

Prediction lat lang is null #38

Open niikocap opened 7 months ago

niikocap commented 7 months ago

When i type some keyword suggestion pops but when i click lat lng is always null description has value

shruti-techindustan commented 7 months ago

@niikocap can you please share your code here

niikocap commented 7 months ago

i just copy paste the example, it seems work i save the lat lng getPlaceDetailWithLatLng from this then use that the item click doesnt work on me since it doesnt give correct data from prediction

niikocap commented 7 months ago

i got one more question can you assign function for cross button ?

shruti-techindustan commented 7 months ago

sure @niikocap

shruti-techindustan commented 7 months ago

@niikocap When you click on list item then under itemClick () -> you will get Prediction object. From prediction object get place_id from this object. please request https://maps.googleapis.com/maps/api/place/details/json?placeid=placeId&key=googleAPIKey this API to check whether latlng is getting or not?

vivektopiya commented 6 months ago

@niikocap Please delete the part isLatLngRequired: false from your code. After making this change, you should be able to obtain the latitude and longitude in the getPlaceDetailWithLatLng function. I hope this clarification is helpful!

ShaunAtSense commented 4 months ago

The itemBuilder returns the event prior to calling getPlaceDetailWithLatLng. Also, getPlaceDetailWithLatLng returns a Future which is not awaited on the onTap event. As a result, your Lat & Lng will return nulls.

@shruti-techindustan @Shrutimahajan If you update the onTap event on the itemBuilder as per below, then you will receive a Lat & Lng for your selected prediction.

onTap: () async {
  var selectedData = alPredictions[index];
  if (index < alPredictions.length) {
    if (widget.isLatLngRequired) {
      await getPlaceDetailsFromPlaceId(selectedData);
    }
    widget.itemClick!(selectedData);  
    removeOverlay();
  }
},