faker.providers.geo¶
- class faker.providers.geo.Provider(generator: Any)¶
基类:
BaseProviderland_coords 数据摘自 geonames.org,遵循 Creative Commons Attribution 3.0 License 许可。坐标为十进制格式,用于地图绘制。国家代码为 Alpha 2 格式 (https://www.nationsonline.org/oneworld/country_code_list.htm)。时区为规范时区 (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)。
- coordinate(center: float | None = None, radius: float | int = 0.001) Decimal¶
可选择将坐标居中并在半径范围内选取一个点。
- 示例:
>>> Faker.seed(0) >>> for _ in range(5): ... fake.coordinate() ... Decimal('26.826999') Decimal('45.792650') Decimal('-158.265114') Decimal('-40.995129') Decimal('94.488524')
- latitude() Decimal¶
- 示例:
>>> Faker.seed(0) >>> for _ in range(5): ... fake.latitude() ... Decimal('13.4134995') Decimal('22.896325') Decimal('-79.132557') Decimal('-20.4975645') Decimal('47.244262')
- latlng() Tuple[Decimal, Decimal]¶
- 示例:
>>> Faker.seed(0) >>> for _ in range(5): ... fake.latlng() ... (Decimal('13.4134995'), Decimal('45.792650')) (Decimal('-79.132557'), Decimal('-40.995129')) (Decimal('47.244262'), Decimal('80.880444')) (Decimal('18.6986795'), Decimal('-17.160223')) (Decimal('37.935520'), Decimal('12.226293'))
- local_latlng(country_code: str = 'US', coords_only: bool = False) Tuple[str, ...] | None¶
返回在 country_code 指定国家/地区陆地上已知的某个位置。默认为 'en_US'。有关可用位置/国家/地区,请参阅 land_coords 列表。
- 示例:
>>> Faker.seed(0) >>> for _ in range(5): ... fake.local_latlng() ... ('40.72371', '-73.95097', 'Greenpoint', 'US', 'America/New_York') ('41.48199', '-81.79819', 'Lakewood', 'US', 'America/New_York') ('30.17746', '-81.38758', 'Palm Valley', 'US', 'America/New_York') ('41.72059', '-87.70172', 'Evergreen Park', 'US', 'America/Chicago') ('33.93113', '-117.54866', 'Norco', 'US', 'America/Los_Angeles')
- location_on_land(coords_only: bool = False) Tuple[str, ...]¶
返回一个随机元组,指定一组保证存在于陆地上的坐标。格式为 (latitude, longitude, place name, two-letter country code, timezone) 传递 coords_only 可返回不带元数据的坐标。
- 示例:
>>> Faker.seed(0) >>> for _ in range(5): ... fake.location_on_land() ... ('40.56754', '-89.64066', 'Pekin', 'US', 'America/Chicago') ('25.13915', '73.06784', 'Sheoganj', 'IN', 'Asia/Kolkata') ('-7.60361', '37.00438', 'Kidodi', 'TZ', 'Africa/Dar_es_Salaam') ('33.35283', '-111.78903', 'Gilbert', 'US', 'America/Phoenix') ('17.54907', '82.85749', 'Elamanchili', 'IN', 'Asia/Kolkata')