none
Is it possible to restrict a location query to a specific geographic region, such as a country? RRS feed

  • Question

  • I'm using the Locations API to resolve a city and iso country code to geographic coordinates. However, when using the following query,

    https://dev.virtualearth.net/dev/REST/v1/Locations?query=BERLIN,DE

    I run into ambiguity issues, since "DE" can also be interpreted as the state code for Delaware, US.


    Is there a way to specify that this is a country code, and not a state code? I tried the following,

    https://dev.virtualearth.net/dev/REST/v1/Locations?countryRegion=DE&query=BERLIN

    but it ignores the query completely, returning coordinates for Germany itself.

    Ricky Brundritt suggested in another thread (below) using "BERLIN, GERMANY" as the query for this specific case; however, other queries are bound to suffer from the same ambiguity, and I'd rather not have to special case Germany here. (https://social.msdn.microsoft.com/Forums/en-US/91b65445-d04e-4719-91b5-f3b92d9437b1/find-a-location-by-query-restricted-to-a-specific-country?forum=bingmapsservices)

    This

    https://dev.virtualearth.net/dev/REST/v1/Locations?countryRegion=DE&locality=BERLIN

    works okay, but I have to guarantee that my query really is a locality before I can use it. (For example,

    https://dev.virtualearth.net/dev/REST/v1/Locations?countryRegion=US&locality=Tulsa International Airport

    does not work.)

    Thanks!

    Tuesday, July 12, 2016 7:16 PM

Answers

  • There is no built in support for limiting the results to a particular country. You can however pass in a bounding box or a point within the country as part of the query which will influence the order of the results to make them more relevant to that location. You can do this by using the userMapView or userLocation parameters: https://msdn.microsoft.com/en-us/library/ff701704.aspx You will still see results outside of this area, but they should be ranked lower.

    The only other option is to append the country name to the URL like you are doing, but as you have found this doesn't work in all cases.


    [Blog] [twitter] [LinkedIn]

    Tuesday, July 12, 2016 7:42 PM