PHP Geocoding question

Posted on 2014-10-26
Last Modified: 2014-10-26
I'm trying to get lat and long when geocoding an address.

For example this address as $address: W Club Blvd,Durham,North-Carolina,27701

Open in new window

This is the code:

// Take the address in a variable
	$address = $attorneysStuff['bizAddr'].','.$attorneysStuff['bizCity'].','.$attorneysStuff['bizState'].','.$attorneysStuff['bizZip'];
$address_url = "$address";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $address_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
$response_a = json_decode($response);
//Print the provided address in Human readable/ complete Postal address;
echo $address_returned = $response_a->results[0]->ADDRESS->address_returned.'<br />';
//Print the Latitude and Longitude of the address
echo $lat = $response_a->geocoding_results[0]->COORDINATES->latitude.'<br />';
echo $long = $response_a->geocoding_results[0]->COORDINATES->longitude;

Open in new window

The problem is echo $address_returned  and echo $lat and echo $long won't print anything: I'm sure there is an error in the print string not in the curl but I can't find it.
Question by:seopti
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 58

Expert Comment

ID: 40405417
Post the json response.

Author Comment

ID: 40405419
When you copy and paste the first string in your browser you can see the json response which is:


    "geocoding_results": {
        "LEGAL_COPYRIGHT": {
            "copyright_notice": "Copyright (c) 2013 Grabenhofen Corporation (Colorado, USA) - All Rights Reserved.",
            "result_distribution": "UNPERMITTED, UNLICENSED",
            "copyright_logo": "",
            "terms_of_service": "",
            "privacy_policy": ""
        "STATUS": {
            "access": "KEY_VALID, ACCESS_GRANTED",
            "status": "SUCCESS"
        "ACCOUNT": {
            "name": "Thomas Kowalewski",
            "email": "",
            "api_key": "c3140ba389a289bd42c51ebe2d72ccc67fb4633c",
            "monthly_due": "75.00",
            "next_due": "2014-11-25 23:06:13",
            "distribution_license": "NONE, UNLICENSED",
            "usage_limit": "100000",
            "used_today": "239",
            "remaining_queries": "99761"
        "PROVIDER": {
            "provider": "LOCAL_FARM",
            "import": "ALREADY_STORED"
        "ADDRESS": {
            "address_provided": "1058 W Club Blvd,Durham,North-Carolina,27701",
            "address_returned": "Northgate Mall, 1058 West Club Boulevard, Durham, NC 27701, USA",
            "accuracy": "VERY ACCURATE"
        "COORDINATES": {
            "latitude": "36.0201168129003",
            "longitude": "-78.9100018570646"
        "STATISTICS": {
            "load_time": "0.38",
            "https_ssl": "DISABLED, INSECURE"

Open in new window

LVL 58

Accepted Solution

Gary earned 500 total points
ID: 40405433
$response_a = json_decode($response);

//Print the provided address in Human readable/ complete Postal address;
echo $address_returned = $response_a->geocoding_results->ADDRESS->address_returned.'<br />';
//Print the Latitude and Longitude of the address
echo $lat = $response_a->geocoding_results->COORDINATES->latitude.'<br />';
echo $long = $response_a->geocoding_results->COORDINATES->longitude;

Open in new window


Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Web Development 6 68
Displaying a google org chart from php/mysql code 27 47
How do I Import CSV File In my PHP Application 29 73
Echo'd value as selected in dropdown 20 44
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question