Improving Geocoding Accuracy using MapQuest Open Data
NickName:Chris Muench Ask DateTime:2014-02-19T08:43:59

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 free solution.

I am getting results for about 40-50% of addresses I try to geocode. (I have tried about 20 so far). (I haven't verified the results of the accuracy of the addresses, just the fact that I got a result).

Is there any way I can improve the geocoding results using their API. I don't want to share addresses as that is private information, but for all the addresses I supply all the parameters except country and address_2.

function geocode_customer($customer_id)
{
    $customer_info = $this->get_info($customer_id);
    $mapquest_api_key = 'MY%API%KEY';       
    $geocode_base_api_url = 'http://open.mapquestapi.com/geocoding/v1/address';

    $params = array();

    $params['key'] = $mapquest_api_key;
    $params['outFormat'] = 'json';
    if ($customer_info->country)
    {
        $params['country'] = $customer_info->country;
    }

    if ($customer_info->state)
    {
        $params['state'] = $customer_info->state;
    }

    if ($customer_info->zip)
    {
        $params['postalCode'] = $customer_info->zip;
    }

    if ($customer_info->city)
    {
        $params['city'] = $customer_info->city;
    }

    if ($customer_info->address_1)
    {
        $street = $customer_info->address_1;

        if ($customer_info->address_2)
        {
            $street.= ' '.$customer_info->address_2;
        }
        $params['street'] = $street ;
    }

    $params['format'] = 'json';

    $params_string = '';
    //url-ify the data for the POST
    foreach($params as $key=>$value) 
    { 
        $value = $key == 'key' ? $value : rawurlencode($value);
        $params_string .= $key.'='.$value.'&'; 
    }
    $params_string = rtrim($params_string, '&');


    $api_url = $geocode_base_api_url.'?'.$params_string;

    $c = curl_init();
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_URL, $api_url);
    $contents = curl_exec($c);
    curl_close($c);

    $resp = json_decode($contents, true);

    if(!empty($resp['results'][0]['locations']))
    {
        $latLng = $resp['results'][0]['locations'][0]['latLng'];
        return $latLng['lat'].','.$latLng['lng'];
    }

    //Default to Denver CO
    return '39.737567,-104.9847179';
}

Copyright Notice:Content Author:「Chris Muench」,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/21868673/improving-geocoding-accuracy-using-mapquest-open-data

More about “Improving Geocoding Accuracy using MapQuest Open Data” related questions

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 Community Edition (open data) for a commercial project

Currently I'm developing an application which uses a map and geocoding functionality. I'm using the mapquest api which works like a charm. As a non-native-speaker I had some trouble understandi...

Show Detail

mapquest geocoding data mismatch

I am new to mapquest, What is the difference b/w open.mapquest.* and mapquest.* ?. As I seen somewhere open.mapquest gives data only from open source data(OSM) with nominatim api. In some cases ...

Show Detail

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

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

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

mapquest cache geocoding result for later use with googlemaps

Can I store/cache result of geocoding via mapquest in mt own DB? I want to retrive Latitude/Longitude via mapquest save in my DB and those coordinates later on for geofencing and show some result...

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

Getting data from JSON (Using Mapquest and PHP)

So, I'm trying to pair Google and MapQuest's geocoding abilities because some address aren't able to be geocoded through Google, but they show up on Mapquest so I want to pair them. I was able to g...

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