def get_place(lat, lng):
    datalist = list()

    Key = Keygen()
    keyAPI = Key.get_key_place()
    if not keyAPI:
        sys.exit()
    url = 'https://maps.googleapis.com/maps/api/place/radarsearch/json?location=' + str(
        lat) + ',' + str(lng) + '&radius=20000&type=neighborhood&key=' + str(
            keyAPI) + ''
    response = requests.get(url)
    data = response.json()
    result = data['results']
    # print(data['results'])

    for x in result:
        # print (x['place_id'])
        datalist.append(x['place_id'])
        # print ("====================")

    url = 'https://maps.googleapis.com/maps/api/place/radarsearch/json?location=' + str(
        lat) + ',' + str(lng) + '&radius=20000&type=sublocality&key=' + str(
            keyAPI) + ''
    response = requests.get(url)
    data = response.json()
    result = data['results']
    # print(data['results'])

    for x in result:
        # print (x['place_id'])
        datalist.append(x['place_id'])
        # print ("#########################################")

    return datalist
Exemple #2
0
def getByPlace(adress, mytype, Name_w_Article):
	Key = Keygen()
	keyAPI = Key.get_key_place()
	if not keyAPI:
		sys.exit()
	url = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input='+str(adress)+'&types=geocode&language=es&key='+str(keyAPI)+''
	types = {"Municipio": ["administrative_area_level_4"],
			"Entidad colectiva" :  ["administrative_area_level_5", "neighborhood"],
			"Otras entidades": ["locality", "neighborhood"],
			"Capital de municipio":["locality"],
			"Entidad singular": ["locality"]}
	print(url)
	response = requests.get(url)
	data = response.json()
	print (types[mytype])
	for objects in data['predictions']:
		if objects['types'][0] in types[mytype] :
			if Name_w_Article.lower().lstrip().strip() == objects['structured_formatting']['main_text'].lower().lstrip().strip():			
				print (objects['place_id'], objects['structured_formatting']['main_text'])
				return objects['place_id']
	return False
     "Otras entidades": "locality",
     "Capital de municipio": "locality",
     "Entidad singular": "locality"
 }
 if doc['12_gmap_type'] == types[doc['25_SNIG_TIPO']]:
     print("YESSS")
 else:
     print("Noooooooo")
     # types = {"Municipio": "administrative_area_level_4",
     # 	"Entidad colectiva" :  "administrative_area_level_5",
     # 	"Otras entidades": "locality",
     # 	"Capital de municipio": "locality",
     # 	"Entidad singular": "locality" }
     # place = get_place_ids_by_address_for_type
     Key = Keygen()
     keyAPI = Key.get_key_place()
     if not keyAPI:
         sys.exit()
     cnf = {'googlemaps': {'geocoding': {'key': keyAPI}}}
     config.set(cnf)
     print(keyAPI)
     spider.gmap_loader._language = language
     print(doc['08_INE_Name_w_Article'], types[doc['25_SNIG_TIPO']])
     dta = spider.get_place_ids_by_address_for_type(
         doc['08_INE_Name_w_Article'] + ', España',
         types[doc['25_SNIG_TIPO']])
     # gmap = {}
     # if objects:
     # 	gmap = objects[0].get_document()
     if len(dta) > 0:
         place_id = dta[0]