I have a simple task but cannot seem to pull it off. I will have a page that allows the user to enter their address and have Google return directions to a destination. So, step number one was to go to the google maps API and see how this is done. So, from their example, I got the following url:
http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false
If you put this url in your browser, you will get a json result. So, my thought was, why can't I call this in a jQuery AJAX request? Is this possible? I have tried the request below but get an 'Access Denied' error in the jQuery script:
$.ajax({
type: "POST",
url: "http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false",
success: function (msg) {
alert(msg);
}
});
Does anyone see a problem with the syntax or know why this doesn't work? And FYI, this is just the first question. I would like for this question to become a great resource for others to create a google map with directions via jquery and ajax without using php (which it seems as though everyone else is using).