Failed to load url in Dom Document?

Style Blizzard

New Member
I'm trying to get latitude and longtitude from google map by giving address. But it's giving error. When I directly copy url to browser url bar. it's giving correct result. If anybody know the answer.Here is my code.\[code\]<?php $key = '[AIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0]';$opt = array ('address' => urlencode('Kolkata,India, ON') ,'output' => 'xml' );$url = 'http://maps.google.com/maps/geo?q='.$opt['address'].'&output='.$opt['output'].'&oe=utf8&key='.$key;$dom = new DOMDocument();$dom->load($url);$xpath = new DomXPath($dom);$xpath->registerNamespace('ge', 'http://earth.google.com/kml/2.0');$statusCode = $xpath->query('//ge:Status/ge:code');if ($statusCode->item(0)->nodeValue =http://stackoverflow.com/questions/12816235/='200') {$pointStr = $xpath->query('//ge:coordinates');$point = explode(",", $pointStr->item(0)->nodeValue);$lat = $point[1];$lon = $point[0];echo '<pre>';echo 'Lat: '.$lat.', Lon: '.$lon;echo '</pre>';}?>\[/code\]Following error has occured:\[code\]Warning: DOMDocument::load(http://maps.google.com/maps/geo? q=Kolkata%252CIndia%252C%2BON&output=xml&oe=utf8&key=%5BAIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0%5D) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\draw\draw.php on line 19Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "http://maps.google.com/maps/geo?q=Kolkata%252CIndia%252C%2BON&output=xml&oe=utf8&key=%5BAIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0%5D" in C:\xampp\htdocs\draw\draw.php on line 19Notice: Trying to get property of non-object in C:\xampp\htdocs\draw\draw.php on line 26\[/code\]
 
Back
Top