简体   繁体   中英

Django : How to get longitude and latitude from google maps user selected adress and save to database

I am new to Django and Python. I want to make a view in which user can open the google maps ( or anything similar), choose a location (put a thumbtack) on map and get the longitude and latitude from this location to save to database. I searched the internet but i am confused about how to do it

Can you please , guide me where to look or what to use? Many thanks for spending your time to help me

Kostas

Google has an API key to access google-map

 api_key = "Your private key for google map here"
 address="address of the selected user"
 api_response = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}'.format(address, api_key))
        api_response_dict = api_response.json()

this will search the address on the map and give you a response back to the 'api_response' variable from this variable you can access the longitude and lattitude of the address given above

api_response_dict = api_response.json() # this line used to covert the response into a dict format/json format

latitude = api_response_dict['results'][0]['geometry']['location']['lat']
longitude = api_response_dict['results'][0]['geometry']['location']['lng']

The Bing Maps APIs include map controls and services that you can use to incorporate Bing Maps in applications and websites. In addition to interactive and static maps, the APIs provide access to other geospatial features such as geocoding, route and traffic data and spatial data sources that you can use to store and query data that has a spatial component, such as store locations.

Step 1: Create a Bing Maps Key

Step 2: Run Python Script

Source : http://helpdoc.info/how-to-get-latitude-longitude-by-using-address-from-bing-api/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM