I am working on integrate Google Maps API to build an autocomplete feature to a textfield in my website.
So i wrote the below function which makes an API call to Google APIs and get the locations.
get_data = function(word, callback){
var google_api = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input="+word+"&types=geocode&
key=AIzaSyCkvES-57OzaaqwnkVb74PwBqjxRbtsNNQ";
console.log(google_api);
$.ajax({
url: google_api,
type: "GET",
dataType: 'jsonp',
cache: false,
success: function(response){
console.log(response);
callback(response);
}
}); }
If I paste the URL generated ( google_api) into a browser bar, it works fine. But the JSONP request as above fails with the below error showing in the browser console. Any ideas on where I am wrong ?
Uncaught SyntaxError: Unexpected token :json?input=cvcxvxcxfdf&types=geocode&key=AIzaSyCkvES-57OzaaqwnkVb74PwBqjxRbtsNNQ&callback=jQuery111…:2
An example of the URL generated is below ( which works well on its own)- https://maps.googleapis.com/maps/api/place/autocomplete/json?input=del&types=geocode&key=AIzaSyCkvES-57OzaaqwnkVb74PwBqjxRbtsNNQ