Package library :: Package pyjamas :: Package gmaps :: Module Geocoder
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.gmaps.Geocoder

 1  # Copyright (C) 2009 Daniel Carvalho <idnael@gmail.com> 
 2  # 
 3  # Licensed under the Apache License, Version 2.0 (the "License"); 
 4  # you may not use this file except in compliance with the License. 
 5  # You may obtain a copy of the License at 
 6  # 
 7  #     http://www.apache.org/licenses/LICENSE-2.0 
 8  # 
 9  # Unless required by applicable law or agreed to in writing, software 
10  # distributed under the License is distributed on an "AS IS" BASIS, 
11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
12  # See the License for the specific language governing permissions and 
13  # limitations under the License. 
14   
15  from __pyjamas__ import JS 
16   
17  from pyjamas.gmaps.Utils import translateGmapsObject, dictToJs #, gmapsPyObjectToJs 
18   
19   
20  GeocoderStatus = JS("$wnd['google']['maps']['GeocoderStatus']") 
21  GeocoderLocationType = JS("$wnd['google']['maps']['GeocoderLocationType']") 
22   
23   
24  geocoderResultsFields = dictToJs( 
25      {"results": 'l', "types": 'l', "address_components": 'l', 
26       "results[]": 'd', "address_components[]": 'd', "geometry": 'd', 
27       "result": 'd'}) 
28   
29   
30  # translates a geocoderResults structure from js to python 
31  # and vice-versa 
32   
33 -def translateGeocoderResults(jsResults, pyToJs=False):
34 return translateGmapsObject(jsResults, "results", \ 35 geocoderResultsFields, pyToJs)
36 37 38 # translates just one element of the geocoderResults 39 # (because it is used inside directionsResults...)
40 -def translateGeocoderResult(jsResult, pyToJs=False):
41 return translateGmapsObject(jsResult, "result", \ 42 geocoderResultsFields, pyToJs)
43 44
45 -class Geocoder:
46
47 - def __init__(self):
48 self.geocoder = JS("new $wnd['google']['maps']['Geocoder']()")
49
50 - def geocode(self, request, callback):
51 52 self.geocoder.geocode(request, 53 lambda jsResults, status: 54 callback(translateGeocoderResults(jsResults), status))
55 56
57 -def GeocoderRequest(**params):
58 return dictToJs(params)
59