Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I just started using the mapQuest Geocoding API and I created a code for searching addresses. The following code alerts "OK" but I can not alert the (lat, lon) coords, even I tried with so many different ways. Can you spot what is wrong? Does this means that the coords are not actually returned? The alerts about the coords are not even alert "undifined"...

Thanks

the code :

function codeAddress(){
    var ad = document.getElementById("address");//get input from form
    $.ajax({
                type: "POST",                
                url: "http://www.mapquestapi.com/geocoding/v1/address?key=Fmjtd******&outFormat=json&inFormat=json&json={location:"+ad+",options:{maxResults:1}}",                                              success: function(response) {
                    alert("OK");//alerts OK, but NONE of the followinng
                    alert(response.results[0].locations[0].location.street);
                    alert(response.results[0].locations[0].location.latLng.lat);
                    alert(response.results[0].latLng.lat);
                    alert(response.results[0].location.latLng.lat);
                    alert(responce.results[0].locations[0].latLng);

                    }})
}

//this is the html form    
<input id="address" type="textbox">    
<input type="button" value="Encode" onClick="codeAddress()">  
share|improve this question
add comment

2 Answers

For Mapquest Geocoding you need to send the format

In the example given you get the full

Take this example and add YOUR_API_KEY

http://www.mapquestapi.com/geocoding/v1/address?key=YOUR_KEY_HERE&callback=renderOptions&outFormat=json&inFormat=json&json={location:{street:%22Lancaster,PA%22},options:{thumbMaps:false,maxResults:1}}

You should be getting the flowing back

Country: US State: PA County: Lancaster City: Lancaster Response Code:A5XAX Lat: 40.03804 Lng: -76.30127

Note: Response Code:A5XAX shows the accuracy

thumbMaps needs to set to false - you only want the info - not the map.

share|improve this answer
add comment

The syntax should be like

alert(response.results[0].locations[0].latLng.lat);

It is that easy. I feel so humilated. I think I should stop coffee for a while...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.