I'm studying AngularJS. I'm trying to get GoogleMapsAPI in JSON response format. but Chrome reports "Uncaught SyntaxError: Unexpected token : ".
So far I am just trying to connect and see the objects information using the following code:
var deferred = $q.defer();
$http.jsonp('https://maps.googleapis.com/maps/api/distancematrix/json?origins=Tokyo&destinations=Kyoto&mode=Driving&sensor=false', {
params: {
callback: 'JSON_CALLBACK'
}
}).success(function(response){
console.dir(data,status,headers,config);
deferred.resolve(data);
}).error(function(data,status,headers,config){
deferred.reject(status);
});
return deferred.promise;
The JSON is coming back in the response, but Chrome reports "Uncaught SyntaxError: Unexpected token : " I keep getting the following error in the console:
Uncaught SyntaxError: Unexpected token : (18:20:02:095 | error, javascript)
at https://maps.googleapis.com/maps/api/distancematrix/json?origins=Tokyo&destinations=Kyoto&mode=Driving&sensor=false&callback=angular.callbacks._0:2
GoogleMapsApi's JSON Response:
{
"destination_addresses" : [ "Kyoto, Kyoto Prefecture, Japan" ],
"origin_addresses" : [ "Tokyo, Japan" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "457 km",
"value" : 456931
},
"duration" : {
"text" : "5 hours 39 mins",
"value" : 20338
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
If I navigate directly to url itself, the JSON is returned and is displayed in the browser.
Any ideas why I can't get this error and I never make it to the success callback?