PDA

View Full Version : Google Places API & Sencha



jdruid
26 Jul 2011, 12:29 PM
Hello,

I am back trying Sencha Touch. I am trying to (what I think is simple) a request to Google for a list of Places that are within GeoCoords. I had a prototype working in iOS and in jQuery and I am trying to port it over into Sencha. I would like the JSON result to be displayed in a Navigation List / Table format.

The problem I am running into is an error on the JSON that is returned from Google.

"Uncaught SyntaxError: Unexpected token :"

I am using Ext.util.JSONP.request to make the request but it appears to be failing on the response. I found an article stating JSONP is not supported by the Google Places API.

If that is the case, what is the workaround? Is there one?

Abdhal
21 Aug 2011, 8:07 PM
Same Problem for me... If any one have a solution please say.....

clabasky
20 Nov 2011, 2:57 PM
Anyone figured this out yet?!? :-/

sandhyakrishnan
16 Dec 2011, 1:56 AM
Any luck so far? Am facing the same issue..

johnecon
25 Jan 2012, 11:46 PM
Exactly the same issue for me..

msarath
2 Feb 2012, 11:31 PM
Anyone of you got solution for this issue, please suggest :(

johnecon
3 Feb 2012, 3:54 AM
I have a solution:

You can make a jsonp request to your server.
-The server will print "Ext.util.JSONP(".
-The server will then get the json file from google and print it.
-The server will print ")"

Here is a code sample:


Ext.util.JSONP.request({
url: 'http://localhost:8080/db/',
callbackKey: 'callback',
params: {
currentLat: getLat(),
currentLon: getLon(),
transaction: 'getGpPlaces'
},
callback: function(result) {
console.log(result)
}

To make this work you have to modify your app.yaml and add the following code:



handlers:
- url: /db/.*
script: db/transaction.py


Then create a db folder under your project's root directory and inside it create the transaction.py
The python code inside transaction.py looks like this:


def geocode(sensor,location,radius,key, **geo_args):
geo_args.update({
'sensor': <sensor>, #true or false
'location': <location>, #lat,lon
'radius': <radius>, #distance in meters
'key': <your app's API key>
})
url = GEOCODE_BASE_URL + '?' + urllib.urlencode(geo_args)
result = simplejson.load(urllib.urlopen(url))
print ''
print 'Ext.util.JSONP.callback('
print simplejson.dumps(result, indent=2)
print ')


Have a look also here (http://gmaps-samples.googlecode.com/svn/trunk/geocoder/python/SimpleParser.py).

Cheers!