Click here to Skip to main content
14,241,305 members
Rate this:
Please Sign up or sign in to vote.
See more:
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.)
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100