Answered by:
Can't use Geodata API with AngularJS $http?

Question
-
I'm trying to get the Geodata API functioning with the $http method in Angular JS. Similarly to jQuery you specify a framework-specific callback which gets used to route the returning data.
&jsonp=JSON_CALLBACK in the javascript is turned into &jsonp=angular.callbacks._0 in the request.
https://platform.bing.com/geo/spatial/v1/public/geodata?spatialFilter=GetBoundary(47.64054,-122.12934,1,'PostCode1',1,1,'en','us')&key=BING_MAPS_KEY&$format=json&jsonp=angular.callbacks._0
It looks like the API doesn't like that, because the return I receive is:
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>BadRequest</code><message xml:lang="en-US">One or more parameters are not valid. jsonp: The string value has an invalid format.</message></error>
I have also been unable to call the API with a GET request, since it returns an access-control-allow-origin error.
I haven't had a problem with any other API's I'm calling to this point. Am I doing something wrong with the Geodata API specifically? Is this just a limitation of the API?
Thanks,
Ben
Tuesday, February 17, 2015 7:01 PM
Answers
-
Additional Reading:
tl;dr - It's an angularJS or API specific problem, depending on who you ask and who doesn't want to change any of their code.
https://github.com/angular/angular.js/issues/1551
Solution for now:
Use jQuery
- Proposed as answer by Ricky_Brundritt Wednesday, February 18, 2015 5:25 PM
- Marked as answer by Ricky_Brundritt Wednesday, February 18, 2015 5:25 PM
- Edited by ABFoxEF Wednesday, February 18, 2015 5:34 PM User -> Use jQuery
Tuesday, February 17, 2015 7:42 PM
All replies
-
Additional Reading:
tl;dr - It's an angularJS or API specific problem, depending on who you ask and who doesn't want to change any of their code.
https://github.com/angular/angular.js/issues/1551
Solution for now:
Use jQuery
- Proposed as answer by Ricky_Brundritt Wednesday, February 18, 2015 5:25 PM
- Marked as answer by Ricky_Brundritt Wednesday, February 18, 2015 5:25 PM
- Edited by ABFoxEF Wednesday, February 18, 2015 5:34 PM User -> Use jQuery
Tuesday, February 17, 2015 7:42 PM -
It does look like a bug in AngularJS. Accessing the GeoData API using JSONP in many other JS frameworks works fine.
http://rbrundritt.wordpress.com
Wednesday, February 18, 2015 5:24 PM -
It does look like a bug in AngularJS. Accessing the GeoData API using JSONP in many other JS frameworks works fine.
http://rbrundritt.wordpress.com
It is and it isn't...
If you call it an Angular bug the solution is for angular to change the way it forms the callback (probably to remove the dot notation).
If you call it a GeoData API bug the solution is for the API to support dot notation in callbacks.
jQuery (and probably the other frameworks) from what I can tell create the custom callback in plain text.
Either way I doubt it will be changed on either end any time soon :D
Wednesday, February 18, 2015 5:34 PM