Reverse Geocoding using Mapquest API and Python
NickName:Gonzalo68 Ask DateTime:2015-08-11T04:59:54

Reverse Geocoding using Mapquest API and Python

Hi Everyone so I am trying to Geocode using the Mapquest API. I want to do reverse geocoding by giving the LAT/LONG CSV and process it through a Python Script using Mapquest API. I created the script below but when I get my output from the script I get no response. Can anyone tinker with my script so that I get the JSON out of it and I can parse the address data from the geocoding to another file. Thanks

Here is my input CSV sample Data

objectID    lat lon
1   52.36732733 4.9491406

My Python Script

import pandas as pd
import json
import requests 

df = pd.read_csv('/Users/albertgonzalobautista/Desktop/Testing_MPQ.csv')

# create new columns
df['geocode_data'] = ''
df['address']=''

# function that handles the geocoding requests

def reverseGeocode(latlng):
    result = {}
    url = 'http://www.mapquestapi.com/geocoding/v1/address?key={1}'
    apikey = 'XXX'
    request = url.format(latlng, apikey)
    data = json.loads(requests.get(request).text)
    if len(data['results']) > 0:
        result = data['results'][0]
    return  result

for i, row in df.iterrows():
    df['geocode_data'][i] = reverseGeocode(df['lat'][i].astype(str) + ',' + df['lon'][i].astype(str))

df.to_csv('test8.csv', encoding='utf-8', index=False)

The output of my script

objectID    lat lon geocode_data
1   52.36732733 4.9491406   {'providedLocation': {}, 'locations': []}

Copyright Notice:Content Author:「Gonzalo68」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31929066/reverse-geocoding-using-mapquest-api-and-python

More about “Reverse Geocoding using Mapquest API and Python” related questions

Reverse Geocoding using Mapquest API and Python

Hi Everyone so I am trying to Geocode using the Mapquest API. I want to do reverse geocoding by giving the LAT/LONG CSV and process it through a Python Script using Mapquest API. I created the script

Show Detail

Parsing data from MapQuest reverse geocoding api in Python?

My code: from urllib import request import json lat = 31.33 ; long = -84.52 webpage = "http://www.mapquestapi.com/geocoding/v1/reverse?key=MY_KEY&callback=renderReverse&location={},{}".f...

Show Detail

Reverse Geocoding for Mapquest SDK on Android

Is there anyway I can reverse Geocode, I have MapQuest SDK(Android) ? I know Android has its own GeoCoder but if I have Lat and Lng from Mapquest and when I reverse geocode from AndroidGeocoder (g...

Show Detail

Reverse geocoding in matlab

I have written a small piece of code to be able to reverse geocode based on lat, long information. I mainly am stuck in 2 ways; Here I have tried to use the google api as I am not sure how to co...

Show Detail

MapQuest Directions API counts transaction for Geocoding

I generated free key for MapQuest API (15,000 free transactions per month). I'm only going to use Directions API and nothing else. What is important that I only want to use it with specified GPS

Show Detail

Using the MapQuest geocoding API to get the correct zoom to an area

I use the MapQuest geocoding API and the Leaflet library to create a map and let users go to a specific location. Can I use this API or library to get the correct zoom levels or the bounds for a sp...

Show Detail

Improving Geocoding Accuracy using MapQuest Open Data

I have written the following function in php to geocode a customers' address from the MapQuest API. I know that google is far better, but I need to use this for a commercial project and want to use a

Show Detail

Mapquest language one forward geocoding

Is there any parameter to add language in Mapquest with forward geocoding? Instead of using nominatim. Thank you!

Show Detail

How do I get the boundingBox for the MapQuest API?

The traffic incidents needs the boundingBox param (https://developer.mapquest.com/documentation/traffic-api/incidents/get/) and it docs use a location that is geocoded, I would assume to get the

Show Detail

Mapquest: This key is not authorized for this service

I am trying to use Geocoding.net to reverse geocode my latitude and longitude to a formatted address. I want a address from MapQuest and not from other providers like Yahoo, google and bing. This i...

Show Detail