$url="https://maps.googleapis.com/maps/api/geocode/xml? address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false&key=..."
$ch = curl_init($url);
$response = curl_exec($ch);
curl_close($ch);
$response = new SimpleXMLElement($response);
$latitude = $response->result->geometry->location->lat;
echo $latitude;
This Returns Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML'
I have tried adding oe=utf-8 to the url but not improving, when I load the website in the browser I can see the result fine althought with the header "This XML file does not appear to have any style information associated with it. The document tree is shown below." How can I reformat this so SimpleXMLElement can read it?
Update: file_get_contents($url); works fine I've tried and with that SimpleXMLElement() can be used, I have also tried adding different curl_setopts but still they dont return the XML file. I am still trying to do it with curl if anyone can help me with this.
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
Thanks