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
1 change: 1 addition & 0 deletions geocoder/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def yandex(location, **kwargs):
"""Yandex Provider

:param ``location``: Your search location you want geocoded.
:param ``apikey``: YANDEX API KEY
:param ``maxRows``: (default=1) Max number of results to fetch
:param ``lang``: Chose the following language:
> ru-RU — Russian (by default)
Expand Down
1 change: 1 addition & 0 deletions geocoder/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
geocodefarm_key = os.environ.get('GEOCODEFARM_API_KEY')
tgos_key = os.environ.get('TGOS_API_KEY')
locationiq_key = os.environ.get('LOCATIONIQ_API_KEY')
yandex_key = os.environ.get('YANDEX_API_KEY')


class CanadapostKeyLazySingleton(object):
Expand Down
4 changes: 3 additions & 1 deletion geocoder/yandex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging

from geocoder.base import OneResult, MultipleResultsQuery
from geocoder.keys import yandex_key


class YandexResult(OneResult):
Expand Down Expand Up @@ -144,14 +145,15 @@ class YandexQuery(MultipleResultsQuery):

_URL = 'https://geocode-maps.yandex.ru/1.x/'
_RESULT_CLASS = YandexResult
_KEY_MANDATORY = False
_KEY = yandex_key

def _build_params(self, location, provider_key, **kwargs):
return {
'geocode': location,
'lang': kwargs.get('lang', 'en-US'),
'kind': kwargs.get('kind', ''),
'format': 'json',
'apikey': provider_key,
'results': kwargs.get('maxRows', 1),
}

Expand Down
1 change: 1 addition & 0 deletions geocoder/yandex_reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _build_params(self, location, provider_key, **kwargs):
'lang': kwargs.get('lang', 'en-US'),
'kind': kwargs.get('kind', ''),
'format': 'json',
'apikey': provider_key,
'results': kwargs.get('maxRows', 1),
}

Expand Down
68 changes: 68 additions & 0 deletions tests/results/yandex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"response": {
"GeoObjectCollection": {
"metaDataProperty": {
"GeocoderResponseMetaData": {
"request": "Ottawa",
"results": "1",
"found": "30"
}
},
"featureMember": [
{
"GeoObject": {
"metaDataProperty": {
"GeocoderMetaData": {
"precision": "other",
"text": "Canada, Ottawa",
"kind": "locality",
"Address": {
"country_code": "CA",
"formatted": "Canada, Ottawa",
"Components": [
{
"kind": "country",
"name": "Canada"
},
{
"kind": "province",
"name": "Ontario"
},
{
"kind": "locality",
"name": "Ottawa"
}
]
},
"AddressDetails": {
"Country": {
"AddressLine": "Canada, Ottawa",
"CountryNameCode": "CA",
"CountryName": "Canada",
"AdministrativeArea": {
"AdministrativeAreaName": "Ontario",
"Locality": {
"LocalityName": "Ottawa"
}
}
}
}
}
},
"name": "Ottawa",
"description": "Canada",
"boundedBy": {
"Envelope": {
"lowerCorner": "-75.803185 45.338299",
"upperCorner": "-75.608583 45.456097"
}
},
"Point": {
"pos": "-75.699583 45.401795"
}
}
}
]
}
}
}
192 changes: 192 additions & 0 deletions tests/results/yandex_batch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"response": {
"GeoObjectCollection": {
"metaDataProperty": {
"GeocoderResponseMetaData": {
"request": "Ottawa",
"results": "3",
"found": "30"
}
},
"featureMember": [
{
"GeoObject": {
"metaDataProperty": {
"GeocoderMetaData": {
"precision": "other",
"text": "Canada, Ottawa",
"kind": "locality",
"Address": {
"country_code": "CA",
"formatted": "Canada, Ottawa",
"Components": [
{
"kind": "country",
"name": "Canada"
},
{
"kind": "province",
"name": "Ontario"
},
{
"kind": "locality",
"name": "Ottawa"
}
]
},
"AddressDetails": {
"Country": {
"AddressLine": "Canada, Ottawa",
"CountryNameCode": "CA",
"CountryName": "Canada",
"AdministrativeArea": {
"AdministrativeAreaName": "Ontario",
"Locality": {
"LocalityName": "Ottawa"
}
}
}
}
}
},
"name": "Ottawa",
"description": "Canada",
"boundedBy": {
"Envelope": {
"lowerCorner": "-75.803185 45.338299",
"upperCorner": "-75.608583 45.456097"
}
},
"Point": {
"pos": "-75.699583 45.401795"
}
}
},
{
"GeoObject": {
"metaDataProperty": {
"GeocoderMetaData": {
"precision": "other",
"text": "United States of America, State of Oklahoma, Ottawa County, Ottawa",
"kind": "hydro",
"Address": {
"country_code": "US",
"formatted": "United States of America, State of Oklahoma, Ottawa County, Ottawa",
"Components": [
{
"kind": "country",
"name": "United States of America"
},
{
"kind": "province",
"name": "State of Oklahoma"
},
{
"kind": "area",
"name": "Ottawa County"
},
{
"kind": "hydro",
"name": "Ottawa"
}
]
},
"AddressDetails": {
"Country": {
"AddressLine": "United States of America, State of Oklahoma, Ottawa County, Ottawa",
"CountryNameCode": "US",
"CountryName": "United States of America",
"AdministrativeArea": {
"AdministrativeAreaName": "State of Oklahoma",
"SubAdministrativeArea": {
"SubAdministrativeAreaName": "Ottawa County",
"Locality": {
"Premise": {
"PremiseName": "Ottawa"
}
}
}
}
}
}
}
},
"name": "Ottawa",
"description": "Ottawa County, State of Oklahoma, United States of America",
"boundedBy": {
"Envelope": {
"lowerCorner": "-95.037481 36.799996",
"upperCorner": "-94.700289 36.998394"
}
},
"Point": {
"pos": "-94.887588 36.874997"
}
}
},
{
"GeoObject": {
"metaDataProperty": {
"GeocoderMetaData": {
"precision": "other",
"text": "United States of America, State of Michigan, Ottawa County, Ottawa",
"kind": "hydro",
"Address": {
"country_code": "US",
"formatted": "United States of America, State of Michigan, Ottawa County, Ottawa",
"Components": [
{
"kind": "country",
"name": "United States of America"
},
{
"kind": "province",
"name": "State of Michigan"
},
{
"kind": "area",
"name": "Ottawa County"
},
{
"kind": "hydro",
"name": "Ottawa"
}
]
},
"AddressDetails": {
"Country": {
"AddressLine": "United States of America, State of Michigan, Ottawa County, Ottawa",
"CountryNameCode": "US",
"CountryName": "United States of America",
"AdministrativeArea": {
"AdministrativeAreaName": "State of Michigan",
"SubAdministrativeArea": {
"SubAdministrativeAreaName": "Ottawa County",
"Locality": {
"Premise": {
"PremiseName": "Ottawa"
}
}
}
}
}
}
}
},
"name": "Ottawa",
"description": "Ottawa County, State of Michigan, United States of America",
"boundedBy": {
"Envelope": {
"lowerCorner": "-86.250583 42.768294",
"upperCorner": "-85.781788 43.118997"
}
},
"Point": {
"pos": "-86.171585 42.910494"
}
}
}
]
}
}
}
64 changes: 64 additions & 0 deletions tests/results/yandex_reverse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"response": {
"GeoObjectCollection": {
"metaDataProperty": {
"GeocoderResponseMetaData": {
"Point": {
"pos": "41.005407 28.978349"
},
"request": "41.005407,28.978349",
"results": "1",
"found": "3"
}
},
"featureMember": [
{
"GeoObject": {
"metaDataProperty": {
"GeocoderMetaData": {
"precision": "other",
"text": "Saudi Arabia, Northern Borders",
"kind": "province",
"Address": {
"country_code": "SA",
"formatted": "Saudi Arabia, Northern Borders",
"Components": [
{
"kind": "country",
"name": "Saudi Arabia"
},
{
"kind": "province",
"name": "Northern Borders"
}
]
},
"AddressDetails": {
"Country": {
"AddressLine": "Saudi Arabia, Northern Borders",
"CountryNameCode": "SA",
"CountryName": "Saudi Arabia",
"AdministrativeArea": {
"AdministrativeAreaName": "Northern Borders"
}
}
}
}
},
"name": "Northern Borders",
"description": "Saudi Arabia",
"boundedBy": {
"Envelope": {
"lowerCorner": "37.812201 27.480507",
"upperCorner": "45.934732 32.221297"
}
},
"Point": {
"pos": "42.666562 29.958972"
}
}
}
]
}
}
}
Loading