I working with Google maps v3, and I want to get the short name of the country where a marker was geocoded. But I can't get the short_name
subchild from the google maps' xml.
The returned xml like this: http://code.google.com/intl/hu/apis/maps/documentation/geocoding/#XML
I would need the "US
" from this example. This is my function:
function codeLatLng(latlng) {
if (geocoder) {
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var str = '';
jq.each(results, function(){
str += this.formatted_address+'|';
});
str = str.split('|');
jq('#address').text(str[0]);
}
});
}
}
But I would need the "short_name
" subchild under the 7th address_component
.
Thanks!
Sorry f开发者_Python百科or my English...
Did you solved your problem? If not try this function:
function codeLatLng(latlng){
if (geocoder) {
geocoder.geocode({
'location': latlng
}, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
var str = '';
var i = 0, len = results.length, loop = true;
while (i < len && loop) {
for (var j = 0, len2 = results[i].address_components.length; j < len2; j++) {
if (results[i].address_components[j].types[0] == 'country') {
str = results[i].address_components[j].short_name;
loop = false;
break;
}
}
i++;
}
jq('#address').text(str);
}
});
}
}
精彩评论