【发布时间】:2013-08-31 14:45:10
【问题描述】:
您好,我的代码附在下面,虽然它是更大代码的一部分
<html>
<head>
<style>
#results{margin-top:100px; width:600px; border:1px solid #000000; background-color:#CCCCCC; min-height:200px;}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<div id="results"></div>
<script>
var input="Taj Mahal India";
var url = "http://maps.googleapis.com/maps/api/geocode/json?address=" + input + "&sensor=false";
var check = $.getJSON(url, function (data) {
console.log("inside getjson");
console.log(data);
$.each(data.results.address_components, function(i,inside){
if(inside.types[0]=="route"){
$("#results").append('<p> route : '+this.long_name +'</p>');
}
if(inside.types[0]=="locality"){
$("#results").append('<p> locality : '+this.long_name +'</p>');
}
if(inside.types[0]=="administrative_area_level_2"){
$("#results").append('<p> administrative area 2 : '+this.long_name +'</p>');
}
if(inside.types[0]=="administrative_area_level_1"){
$("#results").append('<p> administrative area 1 : '+this.long_name +'</p>');
}
if(inside.types[0]=="country"){
$("#results").append('<p> country : '+this.long_name +'</p>');
}
});
});
</script>
</body>
</html>
问题是它不起作用。我非常怀疑我在$.each(data.results.address_components, function(i,inside) 行中做错了什么。
印度泰姬陵的 JSON 在这里 http://maps.googleapis.com/maps/api/geocode/json?address=Taj%20Mahal%20India&sensor=false
【问题讨论】:
-
您能告诉我们您期望它做什么,以及它正在做什么而您不期望吗?
-
@Xymotech 当我在浏览器中运行它时,它不会打印任何东西,它会在 firebug 中引发错误,这超出了我的理解,它说 e in not defined。
-
@henry 成功了,谢谢
标签: javascript jquery json