3

I have been trying to find the latitude and longitude of a list of company-names. For example, the addresses look like this-(1Mobility India Pvt Ltd Pune Maharashtra India), (21st Century Software Solutions Pvt Ltd Visakhapatnam Andhra Pradesh).

I am geocoding using python and I know how to geocode if I am given the complete set of addresses.

For that I use geocoders package from GoogleV3. Using this package however I am able to recover only the latitude and longitude of the city and not the exact location of the company within the city. In Google maps online , however, I can recover the exact lat long for the company.

Does anyone have any experience about which python package to use for batch geocoding when only company names are given or any other way to batch geocode with just names?

  • 1
    Could you do this in two steps, one using Google APIs to find the address and then using Google APIs to find the latitude/longitude of given address? – barrycarter Dec 19 '16 at 17:11
1

Use the google maps API (requires api key)

from urllib.request import urlopen, Request
from bs4 import BeautifulSoup

# use the google map api
import json


url = 'https://maps.googleapis.com/maps/api/geocode/json?address=Braman+Municipal+Utilities'
jsonurl = urlopen(url)

text = json.loads(jsonurl.read())
print ( text['results'][0]["formatted_address"])
print ( text['results'][0]["geometry"]['location']["lat"])
print ( text['results'][0]["geometry"]['location']["lng"])
0

You don't have to install and configure extra packages.

Just hit the google geocode API with the address separated with '+'. It is a get API and will return the response in a JSON. Then extract the information whatever you want.

import requests

response = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA')

resp_json_payload = response.json()

print(resp_json_payload['results'][0]['geometry']['location'])

If it gives any error then just insert the api-key as:

response = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=<API_KEY>')

Make sure your places API key is enabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.