Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery getJSON在查询Google地图时返回null,即使结果有效_Jquery_Json - Fatal编程技术网

jQuery getJSON在查询Google地图时返回null,即使结果有效

jQuery getJSON在查询Google地图时返回null,即使结果有效,jquery,json,Jquery,Json,我似乎无法让这个简单的代码工作: <script type="text/javascript"> $(document).ready(function(){ $.getJSON('http://maps.google.com/maps/api/geocode/json?address=cebu&sensor=false&region=ph', function(results) { alert(results); }); }

我似乎无法让这个简单的代码工作:

<script type="text/javascript">
$(document).ready(function(){ 
    $.getJSON('http://maps.google.com/maps/api/geocode/json?address=cebu&sensor=false&region=ph', 
    function(results) {
        alert(results);
    });
});
</script>
我还需要做什么?我已经反复阅读了jquery手册,但我似乎无法让这个简单的示例起作用

谢谢

第3段: “请注意,您尝试调用的站点需要支持JSON-P输出。”


您确定maps.google.com支持此功能吗

json-p
键(这很有诗意!)是的,它不支持json-p。在Stackoverflow中也发现了这一点:
{
  "status": "OK",
  "results": [ {
    "types": [ "locality", "political" ],
    "formatted_address": "Cebu City, Philippines",
    "address_components": [ {
      "long_name": "Cebu City",
      "short_name": "Cebu City",
      "types": [ "locality", "political" ]
    }, {
      "long_name": "Cebu",
      "short_name": "Cebu",
      "types": [ "administrative_area_level_2", "political" ]
    }, {
      "long_name": "Central Visayas",
      "short_name": "Central Visayas",
      "types": [ "administrative_area_level_1", "political" ]
    }, {
      "long_name": "Philippines",
      "short_name": "PH",
      "types": [ "country", "political" ]
    } ],
    "geometry": {
      "location": {
        "lat": 10.3455617,
        "lng": 123.8969328
      },
      "location_type": "APPROXIMATE",
      "viewport": {
        "southwest": {
          "lat": 10.3016523,
          "lng": 123.8329031
        },
        "northeast": {
          "lat": 10.3894650,
          "lng": 123.9609625
        }
      },
      "bounds": {
        "southwest": {
          "lat": 10.2594350,
          "lng": 123.8668156
        },
        "northeast": {
          "lat": 10.3991826,
          "lng": 123.9401150
        }
      }
    }
  } ]
}