I am trying to use the Bing Maps REST service to get information about a city's location using a city's name. While the query string returns a response when I enter it directly in the browser, I can't seem to do in within my jquery code. I have the following:
var cs = "san diego";
var qs = "http://dev.virtualearth.net/REST/v1/Locations?q=" + cs + "&type=xml&key=MY_BING_MAPS_KEY";
jQuery.getJSON(qs, function(hs){alert(hs)});
According to firebug I am simply getting nothing in response (response code is 200). Any idea what could be going on? I have other REST calls in other parts of my code and there is absolutely no issue there.
The documentation for using the API is here: http://msdn.microsoft.com/en-us/library/ff701711.aspx
Thanks!
**EDIT: Actually there is a way to overcome this by forcing JSONP from bing maps by doing the following:
$.ajax({
url: "http://dev.virtualearth.net/REST/v1/Locations",
dataType: "jsonp",
data: {
key: key,
q: q
},
jsonp: "jsonp",
success: function (data) {
}
});
**
You are trying to make a cross domain ajax call, meaning you are making an ajax call to a domain different than the one running your app! You need to read how to do that. Here is a link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With