I have this function to return bing address suggestions based off a user entered address. I'm already specifying userLocation, but the results are not nearly as accurate as I would imagine they should be. Is there anything extra I should be doing here? I can manually specify the state or postal code if I have to, but I'd rather avoid doing post processing.
For example, typing 111 returns results from 111, NY, 111 Sweden, 111 Denmark. I would like to restrict this to only the US at least, and really only within a few states which I can hardcode. When I manually specify the options for postalCode in the data, it overrides what I've used in query.
var geolocate = function(options) {
$.ajax({
url: "http://dev.virtualearth.net/REST/v1/Locations",
dataType: "jsonp",
data: {
key: "KEY",
q: options.address,
userLocation: options.latitude + ',' + options.longitude,
maxResults: options.maxResults,
},
jsonp: "jsonp",
success: function(data) {
if (options.success instanceof Function) {
options.success(data);
}
},
error: function(xhr, status, text) {
alert('ERROR:\n');
}
});
};
As it turns out, this will actually do what I intended (Unless testing proves otherwise) I was specifying the address as a single param, q, but if I specify addressLine in combination with userLocation, it filters the results as expected.
var geolocate = function(options) {
$.ajax({
url: "http://dev.virtualearth.net/REST/v1/Locations",
dataType: "jsonp",
data: {
key: "KEY",
addressLine: options.address,
countryRegion: 'US',
userLocation: options.latitude + ',' + options.longitude,
maxResults: options.maxResults,
},
jsonp: "jsonp",
success: function(data) {
if (options.success instanceof Function) {
options.success(data);
}
},
error: function(xhr, status, text) {
alert('ERROR:\n\n');
}
});
};
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