One always hears about encapsulation of code and hiding implementation details. And it is clearly a best practice that should be followed strictly.
But rarely do you get a good example of what could go wrong.
Recently, I was alerted to a bug in one of my apps. There was some javascript code that was saving geocoding data after a google places query. All of a sudden one parameter (latitude disappeared). Why?
Well the culprit was this code:
$('#latitude').val(place.geometry.location.Xa);
$('#longitude').val(place.geometry.location.Ya);
location.Xa was now null and location.Ya was returning latitude instead of longitude. And longitude was now in location.Za. What went wrong there?
Google changed the internals of the Location object and how long/lat were represented. Why would they do that, you ask? Because those 2 variables are implementation details. They were never officially supported in the documentation. But the code above was binding to those object internals.
I’m pretty sure that Xa and Ya were supported in an earlier version of Google Maps but became deprecated (I am using v3).
Instead, Google provides accessor methods Location#lat() and Location#lng().
The fix was:
$('#latitude').val(place.geometry.location.lat());
$('#longitude').val(place.geometry.location.lng());
You might ask: why did I have the variable access in the first place? A copy/paste job from stackoverflow

