调用API:Place Id与预期不同(Python) [英] Calling an API: Place Id is different than expected (Python)

查看:70
本文介绍了调用API:Place Id与预期不同(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用API来访问某个位置的地点ID信息。代码返回带有地理信息和地点ID的JSON数据,但我得到的地点ID与我要求查找的地点ID不匹配。地方ID中的前七个字符是:ChIJ18Y。有人可以给我一些关于地方ID的见解吗?我的编码语句有问题吗?提前感谢您的意见!



这是我到目前为止所做的事情:



import urllib

import json



serviceurl ='http://python-data.dr-chuck.net / geojson?sensor = false& address = Madras + University'



而True:

address = raw_input('输入location:')

如果len(地址)< 1:休息



url = serviceurl + urllib.urlencode({'sensor':'false','address':address})

打印'检索',网址

uh = urllib.urlopen(网址)

data = uh.read()

打印'检索' ,len(数据),'字符'



尝试:js = json.loads(str(data))

除外:js =无

如果'status'不在js或js ['status']!='OK':

print'====无法检索==== '

打印数据

继续



print json.dumps(js,indent = 4)



lat = js [results] [0] [geometry] [location] [lat]

lng = js [results] [0] [geometry] [location] [lng]

打印'lat',lat,'lng',lng

location = js ['results'] [0] ['formatted_address']

打印位置





python-data.dr-c huck.net/geojson(这是API端点,它是Google API数据的静态子集。)

I am calling an API to access the place id information of a location. The code is returning the JSON data with the geographical information and place ids, but the place id I am getting does not match the one I am being asked to find. The first seven characters in the place id are: "ChIJ18Y." Could someone please give me some insight on place ids? Is there a problem with my encoding statement? Thank you in advance for your inputs!

Here is what I have done so far:

import urllib
import json

serviceurl = 'http://python-data.dr-chuck.net/geojson?sensor=false&address=Madras+University'

while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break

url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
print 'Retrieving', url
uh = urllib.urlopen(url)
data = uh.read()
print 'Retrieved',len(data),'characters'

try: js = json.loads(str(data))
except: js = None
if 'status' not in js or js['status'] != 'OK':
print '==== Failure To Retrieve ===='
print data
continue

print json.dumps(js, indent=4)

lat = js["results"][0]["geometry"]["location"]["lat"]
lng = js["results"][0]["geometry"]["location"]["lng"]
print 'lat',lat,'lng',lng
location = js['results'][0]['formatted_address']
print location


python-data.dr-chuck.net/geojson (This is the API endpoint, which is a static subset of Google API data.)

推荐答案

没关系。我得到了实际地址的正确地点ID,而不是大学的名称。我认为输入更准确的信息有帮助。我从程序中得到了正确的地址,然后再次运行它以获得正确的地点ID。
Never mind. I get the correct place id for the actual address and not the name of the university. I think entering the more precise information helped. I got the correct address from the program, then ran it again for the right place id.


这篇关于调用API:Place Id与预期不同(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆