如何使用JQUERY

时间:2017-06-03 07:58:30

标签: php jquery html

大家好我试图使用google location api从xml数据中提取城市和州名。

我可以从xml数据中获取完整的地址,我尝试的代码如下。

function get_add(latitude, longitude){
                $.get("http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&sensor=false", function(data){

                        $(data).find("address_component").each(function(){
                                var unitData = $(this).find("long_name").text();
                                //var d = unitData.find("long_name").text();

                                $("#output").html("Latitude : " + latitude + "<br> Longitude: " + longitude + "<br>");
                                $("#output").append(unitData);
                                return false;
                        });     
                });
        }

我自己经过纬度和经度。我得到的数据是完整的地址。

我得到的XML格式如下(示例):

<GeocodeResponse>
     <status>OK</status>
     <address_component>
           <long_name>Bier</long_name>
           <short_name>Bier</short_name>
           <type>administrative_area_level_2</type>
           <type>political</type>
     </address_component>
</GeocodeResponse>

我想从上面提取城市和州名。

提前谢谢你。

0 个答案:

没有答案