0

Possible Duplicate:
google.maps.Geocoder.geocode() geometry.location lat/lng property names change frequently

I use Google Map v3 and its geocoder api in my applicaiton. I use this url to get refer to the api: http://maps.google.com/maps/api/js?key=key&sensor=false

The following code used to work very well:

    geocoder.geocode( 
    {'address': address }, function(data, status) 
    { 

            var lat = data[0].geometry.location.Ya;
            var lng = data[0].geometry.location.Za;
              });

But since the api changed on 18th of Nov, this code cannot get the lat and lng information anymore:

var lat = data[0].geometry.location.Ya;
var lng = data[0].geometry.location.Za;

I need to use:

var lat = data[0].geometry.location.$a;
var lng = data[0].geometry.location.ab;

I understand that the problem can be fixed by:

var latlng = data[0].geometry.location;
var lat = latlng.lng();
var lng = latlng.lat();

But is it weired to keep on changing the variable's name? This happened on 22nd of October, now it is changed again. I am just wondering if anybody had the similar problem before? Is there a Google Map v3 javascript URL with version number so that I don't need to use the latest version? Thanks in advance.

Community
  • 1
  • 1
afterglowlee
  • 11,670
  • 5
  • 22
  • 23

2 Answers2

0

load Google API via:

<!--load Google API-->
<script type="text/javascript" src="https://apis.google.com/js/client.js"></script>

then go to API console, create your new project and enable the Google API you need, in your case Gmaps V3 api (you see on/off buttons to enable services you need )

https://code.google.com/apis/console

itsme
  • 48,972
  • 96
  • 224
  • 345
0

I'm weird why you want to access internal variables. Google changes Javascript library of Google Maps API, even if the same version. And they compile their code. The compiler, which is google closure compiler I think, makes randomized variable names for every time when the user specify "Optimization=Advanced".

To understand the compiler behavior, you can try Closure Compiler at here. http://closure-compiler.appspot.com/home

And this is an example code.

function MyFunc(prefix) {
  this.prefix_ = prefix;
}

MyFunc.prototype.helloWorld = function() {
  alert(this.prefix_ + " world");
};

MyFunc.prototype.sayHello = function() {
  alert(this.prefix_);
};

var myFunc = new MyFunc("Hello");
myFunc.helloWorld();
myFunc.sayHello();

When you specify "Optimization=Simple", you would get like this:

function MyFunc(a){this.prefix_=a}MyFunc.prototype.helloWorld=function(){alert(this.prefix_+" world")};MyFunc.prototype.sayHello=function(){alert(this.prefix_)};var myFunc=new MyFunc("Hello");myFunc.helloWorld();myFunc.sayHello();

But if you specify "Optimization=Advanced", you would get like this:

var a=new function(){this.a="Hello"};alert(a.a+" world");alert(a.a);

In advanced mode, the compiler changes the variable names automatically. That's why the internal variable names are always changed.

wf9a5m75
  • 6,100
  • 3
  • 25
  • 59