Search code examples
javascriptgoogle-geocoder

How would I go about permanently referencing Google geocoding results when the property keys are dynamically changing?


Whenever I geocode and obtain the results, the geometry property names for latitude and longitude get changed every month or so, and I have to rewrite the property name to match the data that the Google geocoder gives me so I can fetch it. What was once Ha and Ia is now Ia and Ja for property names. But I can't be doing this every month because soon I have to deploy the site for the client and I'm not going to be monitoring it every two seconds anymore.

OK so now that I'm faced with the V3 geocoding debacle, is there anyway I can reference the properties of the results dynamically in JavaScript? Has anyone come across a solution?


Solution

  • Just enumerated through the location object treating it as an associative array using

    for(i in results[0].geometry.location)

    and then checking the value of i and doing what I need to do accordingly. I know it might not enumerate in the proper order all the time but it's really the only way to enumerate through dynamically changing property keys. As long as google doesn't change the "length" of the object or put Lng alphabetically before Lat then I'll be set. I know this is dirty and NOT Recommended, but I don't have the time right now. If it breaks in the future then I'll take a look at the prototypically inherited location object as suggested by zigomir and user839721. Just do it their way.