Google Maps question to obtain coordinates in php -
this on php have following variable on array
array ( [0] => { "name": "bravo mario1050 [1] => capital federal [2] => argentina" [3] => "status": { "code": 200 [4] => "request": "geocode" } [5] => "placemark": [ { "id": "p1" [6] => "address": "buenos aires [7] => capital federal [8] => argentina" [9] => "addressdetails": { "accuracy" : 4 [10] => "country" : { "administrativearea" : { "administrativeareaname" : "capital federal" [11] => "locality" : { "localityname" : "ciudad autónoma de buenos aires" } } [12] => "countryname" : "argentina" [13] => "countrynamecode" : "ar" } } [14] => "extendeddata": { "latlonbox": { "north": -34.5349161 [15] => "south": -34.6818539 [16] => "east": -58.2451019 [17] => "west": -58.5012207 } } [18] => "point": { "coordinates": [ -58.3731613 [19] => -34.6084175 [20] => 0 ] } } ] } )
i using arrays, explodes , str_replace obtain -58.3731613, -34.6084175 2 variables, there easy way this?
i have question to, did working, apparently google change because have different result had 1 month ago, question .... know why google changed something?
thanks everything
just in case old code used work:
$longitude = ""; $latitude = ""; $precision = ""; //three parts querystring: q address, output format ( $key = "googlekey"; $address = urlencode(str_replace(',',' ',$calle).$altura.", ".$localidadlist.", argentina"); $url = "http://maps.google.com/maps/geo?q=".$address."&output=csv&key=".$key; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header,0); curl_setopt($ch, curlopt_useragent, $_server["http_user_agent"]); curl_setopt($ch, curlopt_followlocation, 1); curl_setopt($ch, curlopt_returntransfer, 1); $data = curl_exec($ch); curl_close($ch); $latitude= str_replace('point','',$data[20]); $latitude= str_replace('coordinates','',$latitude); $latitude= str_replace('"','',$latitude); $latitude= str_replace(':','',$latitude); $latitude= str_replace('{','',$latitude); $latitude= trim(str_replace('[','',$latitude)); $longitude= trim(str_replace('}','',str_replace('"west": ','',$data[21])));
how 3 lines of code? ;-)
$b = file_get_contents("http://maps.google.com/maps/geo?q=". urlencode("1050+bravo mario,+capital federal,+argentina") ."&oe=utf8&key=abcdefg"); $b = json_decode($b, true); list($longitude,$latitude) = $b['placemark'][0]['point']['coordinates']; echo "longitude: " . $longitude . "<br />latitude: " . $latitude;
please note here, assuming have 1 placemark returned, if expecting more, loop $b['placemark']
variable data.
Comments
Post a Comment