返回英国邮政编码只是Google地图地理编码结果的一部分 [英] Returning the UK Post Code only part of a Google Maps geocode result

查看:109
本文介绍了返回英国邮政编码只是Google地图地理编码结果的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Google Maps API V3示例中获得了以下代码行:

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse

  var full_address = results [1] .formatted_address; 

我想要做的是从这个地址字符串中获得Post Code部分。我该怎么做?



有没有我错过的方法,或者是否存在某种类型的String表达式,可以将这部分剪切掉? p>

谢谢,

A

解决方案

邮编以地址的一部分。下面是你如何在结果中寻找它的例子:

  new google.maps.Geocoder()。geocode {
'address':'20 Broadwick Street,London',
'latLng':google.maps.LatLng(51.5136905,-0.1354)
},
函数(结果,状态){
if(status == google.maps.GeocoderStatus.OK){
address = results [0] .address_components;
for(p = address.length-1; p> ; = 0; p--){
if(address [p] .types.indexOf(postal_code)!= -1){
console.log(address [p] .long_name);
}
}
}
}
);

希望有所帮助。


I have the following line of code from the Google Maps API V3 sample:

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-reverse

var full_address = results[1].formatted_address;

What I want to do is get the Post Code part from this address string. How would I do that?

Is there a method I've missed out on or is there some kind of String expression which would cut that part out for me?

Thanks,

A

解决方案

The postcode is returned as a component of the address. Here is an example of how you might look for it in the result:

new google.maps.Geocoder().geocode({
        'address': '20 Broadwick Street, London',
        'latLng': google.maps.LatLng(51.5136905, -0.1354)
    },
    function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            address = results[0].address_components;
            for (p = address.length-1; p >= 0; p--) {
                if (address[p].types.indexOf("postal_code") != -1) {
                    console.log(address[p].long_name);
                }
            }
        }
    }
);

Hope that helps.

这篇关于返回英国邮政编码只是Google地图地理编码结果的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆