Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Adds support for 0 latitude or 0 longitude #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion js/geocoder.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ export default {
},

geocodePosition(position) {
if (!position || !position.lat || !position.lng) {
if (!position || (!position.lat && position.lat!==0) || (!position.lng && position.lng!==0)) {
return Promise.reject(new Error("invalid position: {lat, lng} required"));
}

2 changes: 1 addition & 1 deletion js/googleApi.js
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ function format(raw) {

export default {
geocodePosition(apiKey, position) {
if (!apiKey || !position || !position.lat || !position.lng) {
if (!apiKey || !position || (!position.lat && position.lat!==0) || (!position.lng && position.lng!==0)) {
return Promise.reject(new Error("invalid apiKey / position"));
}

6 changes: 6 additions & 0 deletions test/unit/geocoder.test.js
Original file line number Diff line number Diff line change
@@ -52,6 +52,12 @@ describe('geocoder', function() {
expect(RNGeocoder.geocodePosition).to.have.been.calledWith(position);
});

it ('returns geocoding results with 0 lat and lng', async function() {
const position = {lat: 0, lng: 0};
await Geocoder.geocodePosition(position);
expect(RNGeocoder.geocodePosition).to.have.been.calledWith(position);
});

it ('does not call google api if no apiKey', function() {
const position = {lat: 1.234, lng: 4.567};
RNGeocoder.geocodePosition = sinon.stub().returns(Promise.reject());
7 changes: 7 additions & 0 deletions test/unit/googleApi.test.js
Original file line number Diff line number Diff line change
@@ -22,6 +22,13 @@ describe('googleApi', function() {
expect(ret).to.eql('yo');
});

it ('position', async function() {
let ret = await GoogleApi.geocodePosition('myKey', {lat: 0, lng: 0});
expect(geocodeRequest).to.have.been.calledWith(
'https://maps.google.com/maps/api/geocode/json?key=myKey&latlng=0,0');
expect(ret).to.eql('yo');
});

it ('address', async function() {
let ret = await GoogleApi.geocodeAddress('myKey', "london");
expect(geocodeRequest).to.have.been.calledWith(