From 1d47c3ce5caf1e3e9861b27010a5a1570fb04434 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 9 Aug 2018 13:27:43 +0300 Subject: [PATCH] Read prediction address also through the geocoder --- .../GeocoderGoogleMaps.js | 7 +++++++ .../LocationAutocompleteInputImpl.js | 15 ++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/LocationAutocompleteInput/GeocoderGoogleMaps.js b/src/components/LocationAutocompleteInput/GeocoderGoogleMaps.js index 57c45763..07e998bb 100644 --- a/src/components/LocationAutocompleteInput/GeocoderGoogleMaps.js +++ b/src/components/LocationAutocompleteInput/GeocoderGoogleMaps.js @@ -36,6 +36,13 @@ class GeocoderGoogleMaps { }); } + /** + * Get the address text of the given prediction. + */ + getPredictionAddress(prediction) { + return prediction.description; + } + /** * Fetch or read place details from the selected prediction. * diff --git a/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js b/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js index e2cfb970..ee3b9e78 100644 --- a/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js +++ b/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { any, arrayOf, bool, func, number, shape, string, oneOfType } from 'prop-types'; +import { any, arrayOf, bool, func, number, shape, string, oneOfType, object } from 'prop-types'; import classNames from 'classnames'; import debounce from 'lodash/debounce'; import { propTypes } from '../../util/types'; @@ -59,6 +59,7 @@ const LocationPredictionsList = props => { rootClassName, className, predictions, + geocoder, highlightedIndex, onSelectStart, onSelectMove, @@ -82,7 +83,7 @@ const LocationPredictionsList = props => { onTouchEnd={() => onSelectEnd(index)} onMouseUp={() => onSelectEnd(index)} > - {prediction.description} + {geocoder.getPredictionAddress(prediction)} ); }; @@ -107,13 +108,8 @@ LocationPredictionsList.defaultProps = { LocationPredictionsList.propTypes = { rootClassName: string, className: string, - predictions: arrayOf( - shape({ - id: string.isRequired, - description: string.isRequired, - place_id: string.isRequired, - }) - ).isRequired, + predictions: arrayOf(object).isRequired, + geocoder: object.isRequired, highlightedIndex: number, onSelectStart: func.isRequired, onSelectMove: func.isRequired, @@ -442,6 +438,7 @@ class LocationAutocompleteInputImpl extends Component {