-2

我想将此代码提供给alert具有透视地址的用户,但由于某种原因它没有执行。有人能指出我正确的方向吗?

谢谢!

<html>
<head>
<title>geoload</title>
<script type="text/javascript" src="http://www.mapquestapi.com/geocoding/v1/reverse?key=MY_DEV KEY GOES HERE=40.0755&lng=-76.329999&output=json&callback=renderGeocode"></script>

<script type="text/javascript">
function renderGeocode(response){
    var location = response.results[0].locations[0];
    alert(location.adminArea5 + ", " + location.adminArea4);
}
</script>
</head>
<body onload=(load"renderGeocode")></body>
</html>
4

2 回答 2

3

你错过了一个+标志:

alert(location.adminArea5 + ", " + location.adminArea4);
                          ^
于 2011-11-17T21:46:26.990 回答
1

不需要正文 onload,因为对 mapquestapi 的调用包含一个回调参数。回调参数是renderGeocode,它将调用同名的javascript函数。请参见下面的代码:

<html>
<head>
<title>geoload</title>
<script type="text/javascript" >
function renderGeocode(response) {
    console.log(response)
} 

</script>
<script type="text/javascript" src="http://www.mapquestapi.com/geocoding/v1/reverse?key=MY_DEV KEY GOES HERE&lat=40.0755&lng=-76.329999&callback=renderGeocode" ></script>
</head>
<body></body>
</html>
于 2012-11-10T23:19:37.163 回答