Restrict searches to one country

5,296 views
Skip to first unread message

Bjornie

unread,
Jul 9, 2009, 5:01:07 AM7/9/09
to Google Maps JavaScript API v3
Hi everyone

I'm trying to restrict my users to search in only one country, but is
this functionality accessible in the version 3 beta?

I'm building up an adress from streetname and city, then adding the
country name to the string - plus I'm trying to restrict the search
via the geocode method of Geocoder. The user are not forced to supply
a city or a street name, one of them should be enough.

I.e;
/* Building up a search string, generating something like 'gade,
Denmark' */
new google.maps.Geocoder().geocode({
address: myAddressString,
country: 'DK'
}, function(results, status) {
...
});

The response object will still include positions in other countries.
From the API Reference:
Geocoder request object :: Properties says: "country | string |
Country code top-level domain within which to search. Optional."

Does anyone have any suggestions on how I can restrict the search
boundaries?

(I have tried to specify the country property with both country codes
and country names)

Best regards,

Barry Hunter

unread,
Jul 9, 2009, 8:32:44 AM7/9/09
to google-map...@googlegroups.com
See the documentation:
http://code.google.com/apis/maps/documentation/v3/services.html#CountryCodes

specifing bounds and/or a country only influence or bias the results
to that area, not restrict.

A better way is just to add ", Denmark" onto the end of the search term.


It used to be the case that doing so unilaturally would break the
geocoder as it couldnt cope if the user had already specified the
country, but apprently now it doesnt object to it being twice so is
safe just to add anyway.
--
Barry

- www.nearby.org.uk - www.geograph.org.uk -

Bjornie

unread,
Jul 9, 2009, 5:22:43 PM7/9/09
to Google Maps JavaScript API v3
Thank you for your answer.

Yes, you are right - specifing bounds or country _should_ influence
the results, but it doesn't.

As I said in my first post I already add ', COUNTRY NAME' to the
search address - but, as an example, if the user searches for
'gade' (street in danish) and I add ', Denmark' to the end of the
string (i.e. the search string now is 'gade, Denmark') and give 'dk'
as country variable in the request, Geocoder gives me locations in USA
and the UK. I get results like 'Denmark St. WA, USA' and so on -
instead of results like 'Vesterbrogade, Copenhagen, Denmark'.

Hopefully I made myself more clear :)

Best regards,



On Jul 9, 2:32 pm, Barry Hunter <barrybhun...@googlemail.com> wrote:
> See the documentation:http://code.google.com/apis/maps/documentation/v3/services.html#Count...
>
> specifing bounds and/or a country only influence or bias the results
> to that area, not restrict.
>
> A better way is just to add ", Denmark" onto the end of the search term.
>
> It used to be the case that doing so unilaturally would break the
> geocoder as it couldnt cope if the user had already specified the
> country, but apprently now it doesnt object to it being twice so is
> safe just to add anyway.
>

Hari K T

unread,
May 3, 2011, 6:27:32 AM5/3/11
to google-map...@googlegroups.com
So did you managed to restrict to that particular country ?

I want to restrict it for a city also :( . Any thoughts ?

Thanks

N.Aleksandrenko

unread,
May 4, 2011, 1:30:28 AM5/4/11
to google-map...@googlegroups.com
String search from ui + ", City, Country";




--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Hari K T

unread,
May 4, 2011, 3:15:58 AM5/4/11
to google-map...@googlegroups.com
Yes I thumbs up and Thank you .
Reply all
Reply to author
Forward
0 new messages