Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions spec/providers/GoogleAPIProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}];
Expand All @@ -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");
});
Expand Down
2 changes: 1 addition & 1 deletion src/Geocoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;},
Expand Down
17 changes: 17 additions & 0 deletions src/providers/GoogleAPIProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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);