It'll be great if faker.js can generate lat/long within a country. Also within a rectangle (or a circle) is appreciated.
They would have to be generated together to limit to anything other then a bounds (rectangle), e.g. faker.geo.point(withinPolygon); For faker.address.[latitude|longitude] it would have to be a range option, e.g. faker.address.latitude([-84, -85]).
Will accept a Pull Request for this functionality.
Let me know if anyone can figure it out.
We've just landed better support for long / lat generation in the latest release.
I'm accepting the challenge, I've forked the repo and as soon as I've spare time I'll work on the PR.
I found this to generate random number within a range, i'm imaging something like:
faker.random.coordinates() // return random
faker.random.coordinates(center, radius) // return in range
And for the latitude and longitude functions something like:
For the coordinates by country is more complicated and I need to think about it.
Any feedback?
maybe of use, still have to test it myself as well:
https://gis.stackexchange.com/a/213898
I tested it by copy-pasting most of this and setting some types where I could as I had to use it in angular-in-memory-web-api. Seems to work fine. I am not the math expert, so I cannot comment on distribution. Invoked it like so this.pointInCircle(_AMS, 2000) with _AMS: { latitude: 52.37403, longitude: 4.88969 } (DD notation aka "decimal degrees"), distance in meters, which looks about right. Cheers 馃嵑 / 馃
i think there's already a good example at https://faker.readthedocs.io/en/master/providers/faker.providers.geo.html
Most helpful comment
They would have to be generated together to limit to anything other then a bounds (rectangle), e.g.
faker.geo.point(withinPolygon);Forfaker.address.[latitude|longitude]it would have to be a range option, e.g.faker.address.latitude([-84, -85]).