Faker.js: Latitude/Longitude within a country [feature request]

Created on 5 Jul 2016  路  6Comments  路  Source: Marak/faker.js

It'll be great if faker.js can generate lat/long within a country. Also within a rectangle (or a circle) is appreciated.

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); For faker.address.[latitude|longitude] it would have to be a range option, e.g. faker.address.latitude([-84, -85]).

All 6 comments

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:

  • lat -> random float between -180, 180
  • lng -> random float between -90, 90

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 馃嵑 / 馃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

minhchu picture minhchu  路  3Comments

adoyle-h picture adoyle-h  路  3Comments

HoustonBass picture HoustonBass  路  6Comments

AlexMiroshnikov picture AlexMiroshnikov  路  4Comments

jamesbrucepower picture jamesbrucepower  路  6Comments