Google Maps API data in new response format


#1

When passing Google Maps API an address, it used to return a HTML formatted response. Given the new format of the response, is there something better than tagdata( to pull the lat & lng of “location”?

     "formatted_address" : "3040 SE 143rd Ave, Portland, OR 97236, USA",
     "geometry" : {
        "bounds" : {
           "northeast" : {
              "lat" : 45.5001223,
              "lng" : -122.5160117
           },
           "southwest" : {
              "lat" : 45.5000205,
              "lng" : -122.5162573
           }
        },
        "location" : {
           "lat" : 45.50007009999999,
           "lng" : -122.5161041
        },
        "location_type" : "ROOFTOP",
        "viewport" : {
           "northeast" : {
              "lat" : 45.5014203802915,
              "lng" : -122.5147855197085
           },
           "southwest" : {
              "lat" : 45.4987224197085,
              "lng" : -122.5174834802915
           }
        }
     },

Or is it time to drop back to standard text funnelling and parsing?


#2

That’s JSON, so if you were using Panorama X, you could use the new JSON functions :slight_smile:

However, you filed this under Panorama “Classic”, so those new functions aren’t available. Parsing JSON can be tricky, especially when the data structure is nested as in this case. However, this wouldn’t be too bad to parse with tagdata(, and that’s probably how I would do it. I’d start with

tagdata(htmlContent,|||"location" : {|||,"}",1)

Then I would probably use another tagdata( to extract the lat, and possibly the after( function to extract the longitude, or tagdata( could be used for that also.


#3

Are you sure that format isn’t still supported?

According to the documentation at

A Geocoding API request takes the following form:

https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters
where outputFormat may be either of the following values:

json (recommended) indicates output in JavaScript Object Notation (JSON); or
xml indicates output in XML

XML is the “old” format, that plays nice with tagdata(.


#4

You are correct Dave. When I attempted to update my query to include the recently required ‘key’, when it did not work at first, I overlooked that the problem was not the XML but rather the new format of the URL. I’ll wait to do the JSON until I convert this db over to Panorama X.