-2

I would like for this code to alert the users with their perspective addresses, but for some reason it's not executing. Can someone point me on the right direction?

Thanks!

<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>
Felix
  • 1
  • 1

2 Answers2

3

You've missed a + sign:

alert(location.adminArea5 + ", " + location.adminArea4);
                          ^
Marcus
  • 12,296
  • 5
  • 48
  • 66
  • Thanks for the reply. I added the + sign and also added onload="load(renderGeocode)", but still no luck. – Felix Nov 17 '11 at 23:00
1

The body onload is not required, as the call to the mapquestapi includes a callback parameter. The callback parameter is renderGeocode which will call the javascript function of the same name. See code below:

<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>
  • you should include a textual explanation to your answer. Not only a code example with a short comment – awenkhh Nov 10 '12 at 23:38