Map/Geo APIs question

Hello Bubble Buddies,

I need to find the zip codes contained within a radius of other zip (or postal) codes … like …

If I say “10 miles of 94109 USA,” I’d also get back 94103, and probably also zip codes in South San Francisco as well …

… and I’d like this to work globally, not only in the United States … it seems the Zip Code API in Bubble is only the US …

The solution that I was going to go with I guess doesn’t have radius check.

Does anybody know how to do this with Google Maps APIs, for example? I can’t seem to find it in their feature list …

Does anybody know a good international radius checker? I have been to Stack Overflow, Google APIs forums, etcetera and I am coming up empty!

Thanks Bubble Buddies,

  • S.

Google Places API can return what you ask for. However, you need to input a GPS coordinate rather than another zip code. (Tip: you can use Geocoding API to turn zip code into GPS coordinate: 开始使用  |  Geocoding API  |  Google for Developers)

You can see the documentation of Places API here: Nearby Search (New)  |  Places API  |  Google for Developers

I have tested the following for example: This request returns a list of postal_codes around a set GPS location within 10 miles radius:

{
  "includedTypes": [
    "postal_code"
    
  ],
  "maxResultCount": 10,
  "locationRestriction": {
    "circle": {
      "center": {
        "latitude": 37.7937,
        "longitude": -122.3965
      },
      "radius": 10
    }
  }
  
}

And this is the response. See that there are two zip codes within that range.

{
  "places": [
    {
      "name": "places/ChIJ49w0El-AhYAR9WVSnuOiWM8",
      "id": "ChIJ49w0El-AhYAR9WVSnuOiWM8",
      "types": [
        "postal_code"
      ],
      "formattedAddress": "San Francisco, CA 94111, USA",
      "addressComponents": [
        {
          "longText": "94111",
          "shortText": "94111",
          "types": [
            "postal_code"
          ],
          "languageCode": "en-US"
        },
        {
          "longText": "San Francisco",
          "shortText": "SF",
          "types": [
            "locality",
            "political"
          ],
          "languageCode": "en"
        },
        {
          "longText": "San Francisco County",
          "shortText": "San Francisco County",
          "types": [
            "administrative_area_level_2",
            "political"
          ],
          "languageCode": "en"
        },
        {
          "longText": "California",
          "shortText": "CA",
          "types": [
            "administrative_area_level_1",
            "political"
          ],
          "languageCode": "en"
        },
        {
          "longText": "United States",
          "shortText": "US",
          "types": [
            "country",
            "political"
          ],
          "languageCode": "en"
        }
      ],
      "location": {
        "latitude": 37.795936200000007,
        "longitude": -122.4000032
      },
      "viewport": {
        "low": {
          "latitude": 37.737043047943466,
          "longitude": -122.40595407106871
        },
        "high": {
          "latitude": 37.807227869417872,
          "longitude": -122.36739405166658
        }
      },
      "googleMapsUri": "https://maps.google.com/?cid=14940870862299096565",
      "utcOffsetMinutes": -420,
      "adrFormatAddress": "\u003cspan class=\"locality\"\u003eSan Francisco\u003c/span\u003e, \u003cspan class=\"region\"\u003eCA\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e94111\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
      "iconMaskBaseUri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet",
      "iconBackgroundColor": "#7B9EB0",
      "displayName": {
        "text": "94111",
        "languageCode": "en-US"
      },
      "shortFormattedAddress": "San Francisco"
    },
    {
      "name": "places/ChIJDXK6UmKAhYARfzuOY6DDgeM",
      "id": "ChIJDXK6UmKAhYARfzuOY6DDgeM",
      "types": [
        "postal_code"
      ],
      "formattedAddress": "San Francisco, CA 94105, USA",
      "addressComponents": [
        {
          "longText": "94105",
          "shortText": "94105",
          "types": [
            "postal_code"
          ],
          "languageCode": "en-US"
        },
        {
          "longText": "San Francisco",
          "shortText": "SF",
          "types": [
            "locality",
            "political"
          ],
          "languageCode": "en"
        },
        {
          "longText": "San Francisco County",
          "shortText": "San Francisco County",
          "types": [
            "administrative_area_level_2",
            "political"
          ],
          "languageCode": "en"
        },
        {
          "longText": "California",
          "shortText": "CA",
          "types": [
            "administrative_area_level_1",
            "political"
          ],
          "languageCode": "en"
        },
        {
          "longText": "United States",
          "shortText": "US",
          "types": [
            "country",
            "political"
          ],
          "languageCode": "en"
        }
      ],
      "location": {
        "latitude": 37.789018299999995,
        "longitude": -122.39150629999999
      },
      "viewport": {
        "low": {
          "latitude": 37.782449057926875,
          "longitude": -122.40352908852206
        },
        "high": {
          "latitude": 37.800181956998415,
          "longitude": -122.38168098330425
        }
      },
      "googleMapsUri": "https://maps.google.com/?cid=16393599212237765503",
      "utcOffsetMinutes": -420,
      "adrFormatAddress": "\u003cspan class=\"locality\"\u003eSan Francisco\u003c/span\u003e, \u003cspan class=\"region\"\u003eCA\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e94105\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUSA\u003c/span\u003e",
      "iconMaskBaseUri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet",
      "iconBackgroundColor": "#7B9EB0",
      "displayName": {
        "text": "94105",
        "languageCode": "en-US"
      },
      "shortFormattedAddress": "San Francisco"
    }
  ]
}

1 Like

@hergin : Thank you SO MUCH for this and I’m going to try to get things sparking. (Love the over-ear headphones!)