Reputation: 4319
I am using the Google Maps Places API for JavaScript, and set my boundaries to Berlin, Germany.
This is my code (I am using a npm-module for it, but as you see in the console.log, the bounds are getting passed correctly):
import React from 'react';
import ReactDOM from 'react-dom';
import Autocomplete from 'react-google-autocomplete';
document.addEventListener('DOMContentLoaded', function() {
ReactDOM.render(<Autocomplete
style={{width: '90%'}}
onPlaceSelected={(place) => {
console.log(place);
}}
types={[]}
bounds={new window.google.maps.LatLngBounds(
new window.google.maps.LatLng(51.2, 13.41),
new window.google.maps.LatLng(52.5200, 10.40)
)}
/>, document.getElementById('mount'));
});
Now, when I try to search for a place nearby, it delivers me a place in India first and then Berlin:
My boundaries are set to Berlin:
So my question is now: Is this behaviour normal or did I get something wrong? I tried to switch the LatLng just out of curiosity, but same result.
Upvotes: 1
Views: 1412
Reputation: 4758
Use these bounds:
new google.maps.LatLngBounds(
new google.maps.LatLng(52.35, 13.1),
new google.maps.LatLng(52.65, 13.8),
)
Upvotes: 0
Reputation: 2584
You should be setting strictBounds
to true
to limit the results to just the bounds. Otherwise you are favouring that area but results can come from outside.
From the API docs:
Upvotes: 2