react-google-maps-jimmy
Version:
React.js Google Maps integration component
74 lines (68 loc) • 1.96 kB
Markdown
### Standalone SearchBox
```jsx
const { compose, withProps, lifecycle } = require("recompose");
const {
withScriptjs,
} = require("react-google-maps-jimmy");
const { StandaloneSearchBox } = require("react-google-maps-jimmy/lib/components/places/StandaloneSearchBox");
const PlacesWithStandaloneSearchBox = compose(
withProps({
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=AIzaSyC4R6AN7SmujjPUIGKdyao2Kqitzr1kiRg&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: `100%` }} />,
containerElement: <div style={{ height: `400px` }} />,
}),
lifecycle({
componentWillMount() {
const refs = {}
this.setState({
places: [],
onSearchBoxMounted: ref => {
refs.searchBox = ref;
},
onPlacesChanged: () => {
const places = refs.searchBox.getPlaces();
this.setState({
places,
});
},
})
},
}),
withScriptjs
)(props =>
<div data-standalone-searchbox="">
<StandaloneSearchBox
ref={props.onSearchBoxMounted}
bounds={props.bounds}
onPlacesChanged={props.onPlacesChanged}
>
<input
type="text"
placeholder="Customized your placeholder"
style={{
boxSizing: `border-box`,
border: `1px solid transparent`,
width: `240px`,
height: `32px`,
padding: `0 12px`,
borderRadius: `3px`,
boxShadow: `0 2px 6px rgba(0, 0, 0, 0.3)`,
fontSize: `14px`,
outline: `none`,
textOverflow: `ellipses`,
}}
/>
</StandaloneSearchBox>
<ol>
{props.places.map(({ place_id, formatted_address, geometry: { location } }) =>
<li key={place_id}>
{formatted_address}
{" at "}
({location.lat()}, {location.lng()})
</li>
)}
</ol>
</div>
);
<PlacesWithStandaloneSearchBox />
```