Getting information from a function [closed]

-1

I want to save the geographic coordinates of an address, in the database. I can do this, but have one though.

I have a function that takes an address and returns the geographical coordinates of it. The problem is that as the function has an "echo" to display the coordinates and it is locking my application. Do you know how to do this function return the result without being "echo" or do you know how to make the application not "stop" when passing through "echo"?

Follow the function:

function getCoordinates($address){

    $address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern

    $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address";

    $response = file_get_contents($url);

    $json = json_decode($response,TRUE); //generate array object from the response from the web

    return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']);

    }

    echo getCoordinates($address);
    
asked by anonymous 10.07.2015 / 01:37

2 answers

1

If this is a file called multiple times, just leave this function in the file and echo the other files if it is not possible, plug the output buffer to avoid the headers error aready sent with ob_start (); >

ob_start();
echo getCoordinates($address);
    
10.07.2015 / 02:03
-1

If you just want debug your code to know what your function is returning, use the following command:

echo '<pre>';
var_dump(getCoordinates($address));
echo '</pre>';

reference

    
10.07.2015 / 05:17