I'm trying to search for a street address using Google Maps API within a specific boundary area. For example, I want Google Maps to search only in Romania, within the boundaries of city - Iasi. I am using php
to give a call to the API and I pass the parameters in the URL like this:
$address = urlencode($address.','.config('maps.state').','.config('maps.country'));
$geocode = file_get_contents('https://maps.google.com/maps/api/geocode/json?address='. $address . '&sensor=true&components=country:RO&key='. env('GOOGLE_MAPS_API_KEY'));
When i try to search for a street that doesn't exists(e.g. toy) it just gives me an random address outside the boundary area. I tried implementing it with html/javascript to see if i can get some success there too, but still it goes outside the boundary area. Is there any way i could implement this using a geoJson?
From the Google Maps API documentation:
In a Geocoding request, you can instruct the Geocoding service to return results biased to a particular region by using the
region
parameter. This parameter takes accTLD
(country code top-level domain) argument specifying the region bias. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions.
So just add ®ion=ro
to the url to add the country bias of Romania.