php - can't get file content for url when grab latitude and longitude -


i want convert given postcode latitude , longitude integrate in cart project. when try grab latitude , longitude google api showing error like,

"we're sorry... ... computer or network may sending automated queries. protect our users, can't process request right now."

what wrong code? code shown below.

function getlatlong($code){  $mapsapikey = 'aizasyc1ky_5lfnl2zq_ot2qgf1vjjtgybluyko';  $query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsapikey;  //---------   // create new curl resource $ch = curl_init();  // set url , other appropriate options curl_setopt($ch, curlopt_url, $query); curl_setopt($ch, curlopt_header, 0);  // grab url , pass browser $data = curl_exec($ch);  // close curl resource, , free system resources curl_close($ch);    //-----------  //$data = file_get_contents($query);  // if data returned  if($data){   // convert readable format   $data = json_decode($data);   $long = $data->placemark[0]->point->coordinates[0];   $lat = $data->placemark[0]->point->coordinates[1];   return array('latitude'=>$lat,'longitude'=>$long);  }else{   return false;  } }   print_r(getlatlong('sw1w 9tq')); 

use useragent

curl_setopt($ch, curlopt_useragent,'mozilla/5.0'); 

also check whether missed or not send http request header. check whether using required parameters(get or post) request.

by way, if using many requests have nothing error. stop sending requests, or limit requests doesn't upset server.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -