0

I'm given the following output from the Google Maps API regarding a specific place (Toronto, in this case):

{
    "html_attributions": [],
    "result": {
        "address_components": [
            {
                "long_name": "Toronto",
                "short_name": "Toronto",
                "types": [
                    "locality",
                    "political"
                ]
            },
            {
                "long_name": "Toronto",
                "short_name": "Toronto",
                "types": [
                    "administrative_area_level_3",
                    "political"
                ]
            },
            {
                "long_name": "Toronto",
                "short_name": "Toronto",
                "types": [
                    "administrative_area_level_2",
                    "political"
                ]
            },
            {
                "long_name": "Ontario",
                "short_name": "ON",
                "types": [
                    "administrative_area_level_1",
                    "political"
                ]
            },
            {
                "long_name": "Canada",
                "short_name": "CA",
                "types": [
                    "country",
                    "political"
                ]
            }
        ],
        "adr_address": "<span class=\"locality\">Toronto</span>, <span class=\"region\">ON</span>, <span class=\"country-name\">Canada</span>",
        "formatted_address": "Toronto, ON, Canada",
        "geometry": {
            "location": {
                "lat": 43.653226,
                "lng": -79.3831843
            },
            "viewport": {
                "northeast": {
                    "lat": 43.85545793597914,
                    "lng": -79.11689708040795
                },
                "southwest": {
                    "lat": 43.58102453761487,
                    "lng": -79.63921897890965
                }
            }
        },
        "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/geocode-71.png",
        "icon_background_color": "#7B9EB0",
        "icon_mask_base_uri": "https://maps.gstatic.com/mapfiles/place_api/icons/v2/generic_pinlet",
        "name": "Toronto",
        "photos": [
            {
                "height": 360,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/111007979254365808386\">reza karami</a>"
                ],
                "photo_reference": "AcJnMuE-6IEIgDYrvOJ2h2k46VjS4WxQFYFs1knPpVP6wzNawQUDAPiVB6sKpBV2KAqCyyFHphOFRYjJ1WtwyKIEfBoAjAHfal2iH6EQ63lEVJITq0Pq-ydcmaRL91RNJ0C02AGmytZKXVtHvMBHPFgkZ_LinVgPjGOsq8KeL-DA0EZivvoi",
                "width": 541
            },
            {
                "height": 4096,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/103495274089486015103\">Bill Chapple</a>"
                ],
                "photo_reference": "AcJnMuHBH4BpZTSYULj4lbb74gQk23jwCh5oFYknfstBjDcRL9oS0tK4N_Y-9EQJwDShXAp-FhxEzrFFH4M1DGgVVflPjzyvFK_Mi8Z3LKuDhsGmm87uSDXE8zbMYX1Sk72STacMHK4DOC24o6eMRC9Vkli-MK7gpniUfVGRlIC3do8jjiY6",
                "width": 3072
            },
            {
                "height": 1800,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/103108653966718782017\">Rami Choullami</a>"
                ],
                "photo_reference": "AcJnMuEhYZYUn7GUJigdig65Qc98n3Uij2VSlivw-fDsVe0xopwRqC_xqqSb_dRof3sf9VqYn73YUK28pHPbKDBI-my3XZPBNlWt5F9HM13pqfMnXPSc8T5MM8OZQsL_K1PIAGYRN7Js3x0ZUV8INrihU_I-WmEjTEq6Bi3qLcGhbLRDLfBJ",
                "width": 4000
            },
            {
                "height": 3456,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/104210009813670010562\">F Williams</a>"
                ],
                "photo_reference": "AcJnMuHYVmzokTVkOHuGpo-QN2pnYpS7ukcJjA7UixhKJjVBXx1-wjL5wkeG3Tv8eguoAdLnSGselLkJwr2Qv9EzIwipTROfpZZi0z9108bSmnDe1p9TaX2HkfFW9ZUlisZcg51_S5pZo7N5Ij1sFg1sGeghEk3inNnp1aKFdVI-eVDTZoex",
                "width": 3456
            },
            {
                "height": 1468,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/117548268339235757288\">Oleksandra Hritsunova</a>"
                ],
                "photo_reference": "AcJnMuHU2xGkrzq68bksmuydqJVs8ICoeFf73lLlcPjLvu-kicll4HzwP1OUOeu3fA7Omu8JNRdne1VfUaPXvlC6zgO6ZFNXDBsNvk5m38KwsxW8Sz34Y_87w6tbA8mvhhMLpBhK2an9ARRSHffnkxO49ZF1atdeT4SlsebPazLAQsQvn2LI",
                "width": 3264
            },
            {
                "height": 2432,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/108861743957161337114\">Eric Lanctot</a>"
                ],
                "photo_reference": "AcJnMuF8aBCc79tUT1d86BTP8TDg6gkseQw3PtJy8RyWGZDYd76agJ8YZ8vvzmhvqqSQ_sZnftXNf2UKMA9Uiq3lOHTfK9hK5oEqXkmkpOgWcciTz1F64PSqd89Vef5S1ghmKw063Vur9-EniG2mO2tRswLkt6dkRWrv96gSLQLmnOV5lCrX",
                "width": 3286
            },
            {
                "height": 1152,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/105908445254134031729\">V. Plat</a>"
                ],
                "photo_reference": "AcJnMuGVJu1soWEH6Bi9JmgS0Jq3rgDWlCFi0FB_-Zt-8H9CDjQI9k1sNFKfER3JQizhy2B_TdobLMQ3r7yuYh7GU8IjlqELjYkVFqvNxLxy-VdmA5aZtXf-StGzcxvNn2p2ET7PDohMI6UyVhSDJ0Rj-QkQnfqTmdj4FhACIHkKF0t0lGrb",
                "width": 2048
            },
            {
                "height": 675,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/104466005256044944108\">Alby Set</a>"
                ],
                "photo_reference": "AcJnMuHAfui01mbVxP86o1HpG_IegxuJiiFzvSxmnjWUCa-c2YOmJFdSlpJ0ZZQaUisd6MCwhRgdVyOrHy0RiUQuONi1Cqpim_6zipNabznO4rFazk4mZLPOFaRQhm38aObknDC4o8PPe4pMp6xatEw8DbgUXq9ngCoGk8ingakw3iPCVz6q",
                "width": 1200
            },
            {
                "height": 640,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/117333352902055366925\">John Chen</a>"
                ],
                "photo_reference": "AcJnMuHHRCy3sK40bVxzGXN1SKTGyMEVJGyQcFg6E9uUPH11PIZC-fPZ9JD6iAFB4-zgqy2OYROq4vBN06d9472gSekYR5eUySVcQhfz3Ru-H9JSCrW_akvKCpp1te2oZWSgRe77Ksjp9YkWK7RHiTuoo9hW6xdPRxJapDZDoBnPjK6y5s7A",
                "width": 1138
            },
            {
                "height": 800,
                "html_attributions": [
                    "<a href=\"https://maps.google.com/maps/contrib/104466005256044944108\">Alby Set</a>"
                ],
                "photo_reference": "AcJnMuEJIJWSlNcQkNlWlaK0z57z3fh--CEKsZZRYkC4Jpf3U9NMTWooVfdn6Qvn1KW_CA5kWNM4Gj8I1aDbJ6L247a8QIE6WpjlDyO6_zQTCqI6QoJl1dBTMc6xVQcyZD9Mp27Oe47RGkIUT_ZGL6P2XyvxkNqaafTl4Fr7qtPu6Thcf0dZ",
                "width": 1200
            }
        ],
        "place_id": "ChIJpTvG15DL1IkRd8S0KlBVNTI",
        "reference": "ChIJpTvG15DL1IkRd8S0KlBVNTI",
        "types": [
            "locality",
            "political"
        ],
        "url": "https://maps.google.com/?q=Toronto,+ON,+Canada&ftid=0x89d4cb90d7c63ba5:0x323555502ab4c477",
        "utc_offset": -300,
        "vicinity": "Toronto",
        "website": "http://www.toronto.ca/"
    },
    "status": "OK"
}

I want to use the data from this response to fetch geocoding data using Overpass Turbo (rather than Google Maps).

I've come up with this query for now (which gives it the place name, "Toronto", and its bbox):

[out:json];
wr(43.58102453761487,-79.63921897890965,43.85545793597914,-79.11689708040795)["name"~"^Toronto$",i];
out tags center;

However, this returns both data about the city itself, but also data about the Toronto sign (which I don't want):

{
  "version": 0.6,
  "generator": "Overpass API 0.7.61.5 4133829e",
  "osm3s": {
    "timestamp_osm_base": "2023-11-08T18:35:45Z",
    "copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
  },
  "elements": [

{
  "type": "way",
  "id": 851806479,
  "center": {
    "lat": 43.6523843,
    "lon": -79.3835677
  },
  "tags": {
    "artwork_type": "sign",
    "name": "TORONTO",
    "name:zh": "TORONTO地標字",
    "tourism": "artwork",
    "wikidata": "Q24883816",
    "wikipedia": "en:3D Toronto sign"
  }
},
{
  "type": "relation",
  "id": 324211,
  "center": {
    "lat": 43.7175248,
    "lon": -79.3762512
  },
  "tags": {
    "admin_level": "6",
    "boundary": "administrative",
    "capital": "4",
    "name": "Toronto",
    "name:ar": "تورونتو",
    "name:az-Arab": "تورونتو",
    "name:azb": "تورونتو",
    "name:bn": "টোরোংটো",
    "name:ca": "Toronto",
    "name:ckb": "تۆرنتۆ",
    "name:de": "Toronto",
    "name:el": "Τορόντο",
    "name:en": "Toronto",
    "name:eo": "Toronto",
    "name:es": "Toronto",
    "name:fa": "تورنتو",
    "name:fr": "Toronto",
    "name:gr": "Τορόντον",
    "name:grc": "Τορόντον",
    "name:he": "טורונטו",
    "name:hi": "टॊरॊंटो",
    "name:hy": "Տորոնտո",
    "name:hyw": "Թորոնթօ",
    "name:ja": "トロント",
    "name:kab-Arab": "تورونتو",
    "name:kk-Arab": "تورونتو",
    "name:kmr": "تۆرۆنتۆ",
    "name:kn": "ಟೊರೊಂಟೋ",
    "name:ko": "토론토",
    "name:ku": "Toronto",
    "name:moh": "Tkaronto",
    "name:mr": "टॊरॊंटो",
    "name:oc": "Toronto",
    "name:oj": "Gichi Kiiwenging",
    "name:pa": "ਟੋਰਾਂਟੋ",
    "name:pl": "Toronto",
    "name:pnb": "ٹورنٹو",
    "name:ps": "ټورنټو",
    "name:pt": "Toronto",
    "name:ru": "Торонто",
    "name:ta": "டொரொண்டோ",
    "name:ug": "تورونتو",
    "name:uk": "Торонто",
    "name:ur": "ٹورانٹو",
    "name:zh": "多伦多",
    "official_name": "City of Toronto",
    "official_name:ar": "مدينة تورونتو",
    "official_name:ckb": "شاری تۆرنتۆ",
    "official_name:ku": "Bajarê Toronto",
    "official_name:ur": "ٹورانٹو کا شہر",
    "place": "city",
    "population": "2731571",
    "population:date": "2016",
    "source:population": "Census Profile. 2011 Census. Statistics Canada Catalogue no. 98-316-XWE",
    "state_capital": "yes",
    "type": "boundary",
    "website": "http://toronto.ca",
    "wikidata": "Q172",
    "wikipedia": "en:Toronto"
  }
}

  ]
}

Given the response from the Google Maps API, how can I use the data to retrieve geocoding data about that specific place, without fluff like the Toronto Sign?

I need to make sure this query is flexible enough to work for not just other cities, but any other kind of search (poi, attraction, city, town, etc.).

2
  • 1
    Filtering properties out of a JSON object is a basic function of any library that manipulates JSON, and isn't particularly GIS-centric.
    – Vince
    Nov 8, 2023 at 23:12
  • @Vince I'm not asking about how to get the actual values from the json.
    – user698515
    Nov 8, 2023 at 23:56

1 Answer 1

1

Let your query be more specific about the features you want it to return.

For example, you can add ["place"="city"] in order to return only cities. This won't work if you want to query for towns or villages, of course. In that case you could change it to ["place"] in order to query for all kinds of places or change it in a way to query for towns, villages etc. only. You can do this with all tags. If you want to query for attractions, then add ["tourism"="attraction"] instead, and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.