开发者

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 l开发者_如何学JAVAatitude 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?


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.


Try using location.lat() or location.lng() functions instead.

I think and hope that calling those functions won't break with new versions...


Using location.lat() and location.lng() solved this problem for me.

.lat() and .lng() are methods that are available when the geocoded result is returned. In my Google Chrome Javascript Console, one can see lat & lng in the results[0].geometry.location.proto array.

For reference: http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLng

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜