Make search work
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import Filters from './Filters';
|
||||
import Listings from './Listings';
|
||||
import { pacSelectFirst } from '../helpers/googleMaps';
|
||||
|
||||
class Main extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -28,13 +29,29 @@ class Main extends React.Component {
|
||||
control.style = "top: 200px;"
|
||||
|
||||
var input = document.getElementById('gmaps-places-input');
|
||||
|
||||
pacSelectFirst(input);
|
||||
var options = {
|
||||
componentRestrictions: {country: "BA"}
|
||||
};
|
||||
var searchBox = new google.maps.places.Autocomplete(input, options);
|
||||
searchBox.addListener('places_changed', function() {
|
||||
console.log('search changed', searchBox.getPlaces());
|
||||
|
||||
searchBox.addListener('place_changed', function() {
|
||||
var place = searchBox.getPlace();
|
||||
|
||||
if (!place.geometry) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (place.geometry.viewport) {
|
||||
map.fitBounds(place.geometry.viewport);
|
||||
|
||||
} else {
|
||||
map.setCenter(place.geometry.location);
|
||||
map.setZoom(18);
|
||||
}
|
||||
});
|
||||
|
||||
control.addEventListener('click', (e) => {
|
||||
this.setState({
|
||||
mapClicked: true
|
||||
|
||||
Reference in New Issue
Block a user