当前位置: 代码迷 >> JavaScript >> jQuery 解析 Google map 经纬度报错,该如何处理
  详细解决方案

jQuery 解析 Google map 经纬度报错,该如何处理

热度:488   发布时间:2012-04-27 11:57:44.0
jQuery 解析 Google map 经纬度报错
大家好,我想通过 Google API 解析地址经纬度。

比如“上海电视台”的请求地址为 http://maps.googleapis.com/maps/api/geocode/json?address=上海电视台&sensor=false

Google 解析成功,返回 JSON 如下:
JScript code

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "上海电视台站",
               "short_name" : "上海电视台站",
               "types" : [ "bus_station", "transit_station" ]
            },
            {
               "long_name" : "静安区",
               "short_name" : "静安区",
               "types" : [ "sublocality", "political" ]
            },
            {
               "long_name" : "上海",
               "short_name" : "上海",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "上海市",
               "short_name" : "上海市",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "中国",
               "short_name" : "CN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "200041",
               "short_name" : "200041",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "中国上海市静安区上海电视台 邮政编码: 200041",
         "geometry" : {
            "location" : {
               "lat" : 31.2308820,
               "lng" : 121.464590
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 31.23223098029150,
                  "lng" : 121.4659389802915
               },
               "southwest" : {
                  "lat" : 31.22953301970850,
                  "lng" : 121.4632410197085
               }
            }
         },
         "types" : [ "bus_station", "transit_station" ]
      }
   ],
   "status" : "OK"
}



上面 Google 返回的 JSON 怎么看都是正确的,但是 Chrome 却报错,如下图:



我的代码为:
HTML code

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset="utf-8">
</head>
<body>
<script>
$.getJSON("http://maps.googleapis.com/maps/api/geocode/json?jsoncallback=?",
  {
    address: "上海电视台",
    sensor: "false",
    format: "json"
  },
  function(data) {
         alert( data);
         alert("请求完成");
  });
</script>

</body>
</html>



真心求教



------解决方案--------------------
ajax请求链接有误? 
没能返回数据啊
  相关解决方案