- function writeLatLng(){
- if($this->owner->Lat == NULL || $this->isChanged('adres')){
- usleep(500000); /* wait 0,5 second per request */
- $Adres = $this->owner->Adres;
- $Plaats = $this->owner->Plaats;
- $Provincie = $this->owner->Provincie;
- $Land = $this->owner->Land;
- $VolledigAdres = $Adres .'+'. $Plaats .'+'. $Provincie .'+'. $Land;
- $zoekAdres = str_replace(" ", "+", "$VolledigAdres");
- $gmURL = "http://maps.googleapis.com/maps/api/geocode/json?address=$zoekAdres&sensor=false";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $gmURL);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 100000);
- $data = curl_exec($ch);
- curl_close($ch);
- $json = json_decode($data);
- echo ("$gmURL <br>");
- $status = $json->status;
- if($status == "OVER_QUERY_LIMIT"){
- echo('OVER_QUERY_LIMIT <br>');
- usleep(500000);
- }else if($status == "ZERO_RESULTS"){
- echo('ZERO_RESULTS <br>');
- }else{
- echo('saved lat&lng <br>');
- $Latitude = $json->results[0]->geometry->location->lat;
- $Longtitude = $json->results[0]->geometry->location->lng;
- $this->owner->Lat = $Latitude;
- $this->owner->Lng = $Longtitude;
- if($this->owner->Provincie == NULL){
- foreach($json->results[0]->address_components as $v){
- if (in_array("administrative_area_level_1",$v->types)){
- $this->owner->Provincie = $v->long_name;
- }
- }
- }
- }
- }
- }