diff --git a/spec/providers/GoogleAPIProvider.spec.js b/spec/providers/GoogleAPIProvider.spec.js index 2a2b9f7..a66a851 100644 --- a/spec/providers/GoogleAPIProvider.spec.js +++ b/spec/providers/GoogleAPIProvider.spec.js @@ -32,6 +32,27 @@ describe("Google API Geocoder Provider raw result to Geocoded mapping tests", fu location: { lat: 38.8978378, lng: -77.0365123 + }, + bounds: { + northeast: { + lat: 38.8989583802915, + lng: -77.03538596970849 + }, + southwest: { + lat: 38.8962604197085, + lng: -77.0380839302915 + } + }, + location_type: "ROOFTOP", + viewport: { + northeast: { + lat: 38.8989583802915, + lng: -77.03538596970849 + }, + southwest: { + lat: 38.8962604197085, + lng: -77.0380839302915 + } } } }]; @@ -48,6 +69,10 @@ describe("Google API Geocoder Provider raw result to Geocoded mapping tests", fu expect(geocoded.getCoordinates()).toEqual([38.8978378, -77.0365123]); }); + it ("maps bounds correctly", function() { + expect(geocoded.getBounds()).toEqual([[ 38.8962604197085, -77.0380839302915], [38.8989583802915, -77.03538596970849]]); + }); + it ("maps street number correctly", function() { expect(geocoded.getStreetNumber()).toEqual("1600"); }); diff --git a/src/Geocoded.js b/src/Geocoded.js index f7b8cc9..b7b709d 100644 --- a/src/Geocoded.js +++ b/src/Geocoded.js @@ -11,7 +11,7 @@ if (typeof GeocoderJS === "undefined" && typeof require === "function") { getCoordinates: function() {return[this.latitude, this.longitude];}, getLatitude: function() {return this.latitude;}, getLongitude: function() {return this.longitude;}, - getBounds: function() {}, + getBounds: function() { return this.bounds; }, getStreetNumber: function() {return this.streetNumber;}, getStreetName: function() {return this.streetName;}, getCity: function() {return this.city;}, diff --git a/src/providers/GoogleAPIProvider.js b/src/providers/GoogleAPIProvider.js index fe0dec1..223cac4 100644 --- a/src/providers/GoogleAPIProvider.js +++ b/src/providers/GoogleAPIProvider.js @@ -84,6 +84,10 @@ if (typeof GeocoderJS === "undefined" && typeof require === "function") { geocoded.latitude = result.geometry.location.lat; geocoded.longitude = result.geometry.location.lng; + if(result.geometry.bounds) { + geocoded.bounds = parseBounds(result.geometry.bounds); + } + for (var i in result.address_components) { for (var j in result.address_components[i].types) { switch (result.address_components[i].types[j]) { @@ -108,4 +112,17 @@ if (typeof GeocoderJS === "undefined" && typeof require === "function") { return geocoded; }; + + function parseBounds(boundsData) { + var sw, ne; + + sw = boundsData.southwest; + ne = boundsData.northeast; + + return [ + [sw.lat, sw.lng], + [ne.lat, ne.lng] + ]; + } + })(GeocoderJS);