get all postcode by enter first 3 digit.

nikhil gaikwad 6 Reputation points
2022-09-29T11:53:27.227+00:00

I want to get all postcode boundaries by entering 103XX NY USA and it should plot all the postal codes withn New yorks state starting with 10301 to 10399

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
614 questions
{count} vote

1 answer

Sort by: Most helpful
  1. rbrundritt 15,706 Reputation points Microsoft Employee
    2022-09-29T15:27:48.083+00:00

    The search APIs are designed to try and find the most likely results, not all possible results. So you would have to search for each individual postal code to find out if it exists. Here are some ways to do this:

    If using Azure Maps:

    1. Make a batch call to the address search API: https://learn.microsoft.com/en-us/rest/api/maps/search/post-search-address-batch-sync?tabs=HTTP You can use the synchronous service since it has a limit of 100 addresses and that's how many you would have to process. This API takes the same kind of queries you would pass into the regular address search API, I recommend using the structured format for this scenario: https://learn.microsoft.com/en-us/rest/api/maps/search/get-search-address-structured?tabs=HTTP Be sure to add a country code as there are other countries that have the same format for postal codes (There are a lot of overlapping postal code/zip codes between US and Poland). You can also limit the results to 1 for each request as that is most likely all you will need and will make the response smaller and faster.
    2. Take the response from the batch search and for those that did find a valid postal code, retrieve the boundary ID from the result (dataSources -> geometry -> id). Pass up to 20 of these into the get search polygon API: https://learn.microsoft.com/en-us/rest/api/maps/search/get-search-polygon?tabs=HTTP (you will have to make a few calls to this API since it will only retrieve up to 20 results at a time, you can make those requests in parallel).

    The following is a similar example: https://samples.azuremaps.com/?sample=search-for-boundaries Pass in "13901, US" as test.

    If using Bing Maps:

    1. Make a request for each postcode to the geodata API. https://learn.microsoft.com/en-us/bingmaps/spatial-data-services/geodata-api

    Using Azure Maps would require making up to 6 requests (1 batch search, 5 for boundaries).
    Using Bing Maps would require making 100 requests, one for each postcode. It would likely be slower to make more requests, however, there is an option to select the resolution of the polygons returned, whereas Azure Maps only returns full resolution polygons which can be large in some cases (postcodes however are usually fairly simple shapes.

    1 person found this answer helpful.