Skip to content

Commit

Permalink
Merge pull request #244 from dippi/patch-1
Browse files Browse the repository at this point in the history
Bing Reverse Geocoding
  • Loading branch information
nchaulet authored Feb 7, 2018
2 parents 65fac43 + ae35710 commit 2e885e2
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/geocoder/virtualearth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,37 @@ VirtualEarthGeocoder.prototype._geocode = function(value, callback) {
});
};

/**
* Reverse geocoding
* @param {lat:<number>, lon:<number>} lat: Latitude, lon: Longitude
* @param <function> callback Callback method
*/
VirtualEarthGeocoder.prototype._reverse = function(value, callback) {

var _this = this;

var params = {
key: this.options.apiKey
};

var endpoint = this._endpoint + "/" + value.lat + "," + value.lon;

this.httpAdapter.get(endpoint, params, function(err, result) {
if (err) {
return callback(err);
} else {
var results = [];

for(var i = 0; i < result.resourceSets[0].resources.length; i++) {
results.push(_this._formatResult(result.resourceSets[0].resources[i]));
}

results.raw = result;
callback(false, results);
}
});
}

VirtualEarthGeocoder.prototype._formatResult = function(result) {
return {
'latitude' : result.point.coordinates[0],
Expand All @@ -58,7 +89,8 @@ VirtualEarthGeocoder.prototype._formatResult = function(result) {
'city' : result.address.locality,
'state' : result.address.adminDistrict,
'zipcode' : result.address.postalCode,
'streetName': result.address.addressLine
'streetName': result.address.addressLine,
'formattedAddress': result.address.formattedAddress
};
};

Expand Down

0 comments on commit 2e885e2

Please sign in to comment.