/** * return lat and lon from given location in the session * @param string * @return array */ public function getGeoDataFromAddress($address = '') { $address = trim($address); $geodata = array(); if (strlen($address) < 1) { return $geodata; } require_once TL_ROOT . '/' . BM_PATH . '/libs/google_maps_api.php'; $geo = new \googleGeoData(); $json = $geo->getGeoData($address); // now, process the JSON string $data = json_decode($json); if (strtolower($data->status) == 'ok') { if (count($data->results[0]->geometry->location) > 0) { $geodata['lat'] = $data->results[0]->geometry->location->lat; $geodata['lon'] = $data->results[0]->geometry->location->lng; } } // print_r($data); // exit(); return $geodata; }
/** * set all geolocation if its empty * @param \DataContainer */ public function setAllGeoLatLon(DataContainer $dc) { $resObj = $this->Database->prepare('SELECT * FROM `tl_bm_stores` WHERE lat=0 OR lon=0')->execute(); if ($resObj->numRows > 1) { require_once TL_ROOT . '/' . BN_PATH . '/libs/google_maps_api.php'; while ($resObj->next()) { $addressStr = urlencode($resObj->strasse . ' ' . $resObj->hausnummer . ', ' . $resObj->plz . ' ' . $resObj->ort . ', Deutschland'); $geo = new googleGeoData(); $json = $geo->getGeoData($addressStr); $data = json_decode($json); if (strtolower($data->status) == 'ok') { if (count($data->results[0]->geometry->location) > 0) { $set = array('lat' => $data->results[0]->geometry->location->lat, 'lon' => $data->results[0]->geometry->location->lng); $this->Database->prepare('UPDATE `tl_bm_stores` %s WHERE id=?')->set($set)->execute($resObj->id); } } } } }