jQuery getJSON()不适用于Google maps api
我对JSON和谷歌地图都是新手。所以请告诉我我错过了什么jQuery getJSON()不适用于Google maps api,jquery,json,google-maps-api-3,Jquery,Json,Google Maps Api 3,我对JSON和谷歌地图都是新手。所以请告诉我我错过了什么 <!DOCTYPE html> <html> <head> <script src="https://maps.googleapis.com/maps/api/js?v=3.15&sensor=false"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jqu
<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?v=3.15&sensor=false"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$function({
$("#search").click(function(){
$.getJSON("http://maps.googleapis.com/maps/api/geocode/json?address=awan%20town&sensor=false",function(result){
$.each(result,function(i,field){
$("#map-canvas").append(field + " " );
});
});
});
});
</script>
</head>
<body>
<button id="search">Search</button>
<div id="map-canvas" style="width:100%;height:100%;"></div>
</body>
</html>
$function({
$(“#搜索”)。单击(函数(){
$.getJSON(“http://maps.googleapis.com/maps/api/geocode/json?address=awan%20town&sensor=false,函数(结果){
$.each(结果、函数(i、字段){
$(“#地图画布”).append(字段+”);
});
});
});
});
搜寻
尝试将代码包装到DOM就绪处理程序$(function(){…})中
要确保在执行jQuery代码之前正确加载了所有DOM元素,请执行以下操作:
$(function () {
$("#search").click(function () {
$.getJSON("http://maps.googleapis.com/maps/api/geocode/json?address=awan%20town&sensor=false", function (result) {
$.each(result, function (i, field) {
$.("#map-canvas").append(field + " ");
});
});
});
});
您还需要更改:
$.("#search")
$.("#map-canvas")
致:
这里的选择器前面不需要
。您希望从返回的JSON中获取哪些字段?我想我编写的代码将从该URL返回所有字段,实际上,我想了解任何具体的领域如何做到这一点,我建议您学习关于JSON的基本教程,以便更好地了解JSON的工作原理。我在w3school上学习过,但现在如果您只是更正我的代码,请说我想访问格式化的_地址,我是如何做到的?
$("#search")
$("#map-canvas")