提问人:samarjit singh 提问时间:11/4/2023 最后编辑:Chrissamarjit singh 更新时间:11/4/2023 访问量:11
未从 google place API 获取formatted_address
not getting formatted_address from google place API
问:
useEffect(() => {
autoCompleteRef.current = new window.google.maps.places.Autocomplete(inputRef.current, options);
autoCompleteRef.current.addListener('place_changed', async function () {
const place = await autoCompleteRef.current.getPlace();
console.log('Selected Place: ', place);
const address = place.address_components;
const extractedAddress = {
streetName: address.find((comp) => comp.types.includes('route'))?.long_name || '',
city: address.find((comp) => comp.types.includes('locality'))?.long_name || '',
province:
address.find((comp) => comp.types.includes('administrative_area_level_1'))?.long_name ||
'',
country: address.find((comp) => comp.types.includes('country'))?.long_name || '',
countryCode: address.find((comp) => comp.types.includes('country'))?.short_name || '',
postalCode: address.find((comp) => comp.types.includes('postal_code'))?.long_name || '',
fullAddress: place.formatted_address || '',
};
setExtractedAddress(extractedAddress);
});
}, []);
在上面的代码中,为什么我是fullAddress作为空字符串
尝试了所有可用的方法
答: 暂无答案
评论