1

著者は次のように述べています。Google Geocoding Web サービスのバージョン 3 も実装されており、邪魔にならない JavaScript アプローチをさらに有効にします。しかし、私は彼らのサイトで例を見つけることができません. 誰かが以前にそれを使用したことがありますか?

4

1 に答える 1

0

簡単な例を次に示します。私はdjango-gmapi以前に使用したことがないので、これは最善のアプローチではないかもしれません。

>>> # import the Geocoder class and instantiate it
>>> from gmapi.maps import Geocoder
>>> geocoder = Geocoder()
>>> # Let's geocode the Stack Exchange address!
>>> stack_exchange_hq = "One Exchange Plaza, 26th Floor, New York, NY"
>>> results, status_code = geocoder.geocode({'address': stack_exchange_hq })
>>> print results
{'address_components': [{'long_name': '1',
                         'short_name': '1',
                         'types': ['street_number']},
                        {'long_name': 'Exchange Plaza',
                         'short_name': 'Exchange Plaza',
                         'types': ['route']},
                        {'long_name': 'Downtown',
                         'short_name': 'Downtown',
                         'types': ['neighborhood', 'political']},
                        {'long_name': 'Manhattan',
                         'short_name': 'Manhattan',
                         'types': ['sublocality', 'political']},
                        {'long_name': 'New York',
                         'short_name': 'New York',
                         'types': ['locality', 'political']},
                        {'long_name': 'New York',
                         'short_name': 'New York',
                         'types': ['administrative_area_level_2',
                                   'political']},
                        {'long_name': 'New York',
                         'short_name': 'NY',
                         'types': ['administrative_area_level_1',
                                   'political']},
                        {'long_name': 'United States',
                         'short_name': 'US',
                         'types': ['country', 'political']},
                        {'long_name': '10006',
                         'short_name': '10006',
                         'types': ['postal_code']}],
 'formatted_address': '1 Exchange Plaza, New York, NY 10006, USA',
 'geometry': {'location': {'arg': [40.707183, -74.013402], 'cls': 'LatLng'},
              'location_type': 'ROOFTOP',
              'viewport': {'arg': [{'arg': [40.705834, -74.014751],
                                    'cls': 'LatLng'},
                                   {'arg': [40.708532, -74.012053],
                                    'cls': 'LatLng'}],
                           'cls': 'LatLngBounds'}},
 'partial_match': True,
 'types': ['street_address']}

>>> # look at the first (and only) result
>>> result = results[0]
>>> lat, lng = result['geometry']['location']['arg']
>>> print lat, lng
40.707183 -74.013402

それをGoogleマップに貼り付けると、私たちが望んでいたOne Exchange Plazaが得られます.

上記の結果を解析するときにエラーをキャッチしていないことに注意してください。アプリはおそらく結果をデータベースにキャッシュする必要があります。これにより、クエリのジオコーディングによってページの読み込みが遅くなったり、API の制限に達したりしなくなります。

于 2011-11-16T01:14:39.200 に答える