$print = 1; $formatted_addressGMAP = $addressInput; } else { // FROM GMAP echo "<br> Call to GMAP: " . $loc . ', ' . $defaultPlaceTitle . ', ' . $defaultPlace['address']['country']; $logCallToGMap++; echo '<br>loc' . $loc; echo '<br>laville' . $laville; echo '<br>$defaultPlace title' . $defaultPlaceTitle; echo '<br>$defaultPlace country' . $defaultPlace['address']['country']; echo '<br>$lieu' . $lieu; //$gQuery = urlencode(utf8_decode(suppr_accents($loc.( (strlen($laville)> 0 && $laville != $defaultPlaceTitle && !in_array($loc,$ville) ) ? ', '.$laville:'').', '.$defaultPlaceTitle.'. '.$defaultPlace['address']['country']))); $gQuery = urlencode(utf8_decode(suppr_accents($loc . (strlen($laville) > 0 && $laville != $defaultPlaceTitle && preg_match('/^' . $loc . '$/', $laville) === FALSE ? ', ' . $laville : '') . ', ' . $defaultPlaceTitle . ' ' . $defaultPlace['address']['country']))); //echo 'LIEU'.sizeof($lieu); if (sizeof($lieu) == 0) { $resGMap = getLocationGMap($gQuery, 'PHP', 1, $conf); } else { $resGMap = getPlaceGMap($gQuery, 'PHP', 1, $conf); } echo '___<br>'; if (!empty($resGMap) && $resGMap['formatted_address'] != $defaultPlaceTitle . ', ' . $defaultPlace['address']['country']) { echo "<br> GMAP found the coordinates of this location ! "; // check if the result is in the zone $zoneObj = new Zone(); $zoneNums = $zoneObj->findNumByLocation(array('lat' => $resGMap['location'][0], 'lng' => $resGMap['location'][1])); if (!in_array($feed['zone'], $zoneNums)) { echo "<br><b>Err:</b>Location found is not in the feed zone ( " . $feed['zone'] . " )"; $status = 12; $print = 0; } else { $status = 1;
function saveToMongoDB($locationQuery = "", $debug, $flagUpdate = false) { $res = array('duplicate' => 0, 'insert' => 0, 'locErr' => 0, 'update' => 0, 'callGMAP' => 0, "error" => 0, 'record' => array()); $this->setFilesourceId(); $record = array("title" => $this->title, "content" => $this->content, "thumb" => $this->thumb, "origin" => $this->origin, "filesourceId" => $this->filesourceId, "access" => $this->access, "licence" => $this->licence, "outGoingLink" => $this->outGoingLink, "yakCat" => $this->yakCat, "yakTag" => $this->yakTag, "creationDate" => new MongoDate(gmmktime()), "lastModifDate" => new MongoDate(gmmktime()), "location" => $this->location, "address" => $this->address, "formatted_address" => $this->formatted_address, "contact" => $this->contact, "status" => $this->status, "user" => $this->user, "zone" => $this->zone); //print_r($record); $doublon = $this->getDuplicated($this->title, $this->zone, $this->status); //var_dump($doublon); // if no duplicated if (empty($doublon)) { // if we asked for a geoloc if (strlen($locationQuery) > 0) { //locationQuery="sdfsdfsd"; //$res=array(); $this->getLocationFromQuery($locationQuery, $res); } //var_dump($record);exit; $resSave = $this->savePlace($record); //print_r($resSave); $res['record'] = $record; // TODO : cast to array ??? $res['error'] = $resSave['error']; $this->placeColl->ensureIndex(array("location" => "2d")); $this->placeColl->ensureIndex(array("title" => 1, "status" => 1, "zone" => 1)); if (empty($res['error'])) { $res['insert'] = 1; } } else { // if already in db $res['duplicate'] = 1; $res['record'] = $doublon; if ($flagUpdate == 1) { // if we are asked to update $record = $res['record']; if (strlen($locationQuery) > 0) { // if we are asked to get the location $loc = getLocationGMap(urlencode(utf8_decode(suppr_accents($locationQuery))), 'PHP', $debug); $res['callGMAP'] = 1; $record['location'] = $loc['location']; $record['address'] = $loc['address']; $record['formatted_address'] = $loc['formatted_address']; } $this->placeColl->update(array("_id" => $doublon['_id']), $record); $res['update'] = 1; } } return $res; }
function getLocation($query, $debug) { $loc = getLocationGMap(urlencode(utf8_decode(suppr_accents($query))), 'PHP', $debug); //print_r($loc); if ($loc['status'] == "OK") { $this->location->lat = $loc["location"][0]; $this->location->lng = $loc["location"][1]; return true; } print "Gmap error for address : " . $query . "<br>"; return false; }
$placeColl = $db->place; $batchlogColl = $db->batchlog; $yakdicoYakCatId = "5056b7aafa9a95180b000000"; $countInsert = 0; $row = 0; $countGMap = 0; foreach ($ontolgyXML as $key0 => $value) { foreach ($value as $key => $value2) { foreach ($value2->attributes() as $attributeskey => $streetNameArray) { $streetName = (string) $streetNameArray; echo "<br>" . $attributeskey . "=" . $streetName; // CHECK IF DATA EXISTS IN DB $res = $placeColl->findOne(array('title' => $streetName)); if (empty($res)) { echo "<br>Location not found in DB, we start inserting..."; $resGMap = getLocationGMap(urlencode(utf8_decode(suppr_accents($streetName . ', Paris, France'))), 'PHP', 1); $geolocGMAP = $resGMap['location']; $addressGMAP = $resGMap['address']; $statusGMAP = $resGMap['status']; echo 'STATUS' . $statusGMAP; $countGMap++; if (!empty($geolocGMAP) && $statusGMAP == "OK") { $status = 1; echo "<br>Found location with GMap<br>"; } else { echo "<br>GMap failed to find location. The place is stored in status 10.<br>GMAP STATUS = " . $statusGMAP; $status = 10; } $countInsert++; var_dump($streetName); $place = array("title" => $streetName, "content" => "", "thumb" => "", "origin" => "ontology yakdico", "access" => 2, "licence" => "Yakwala", "outGoingLink" => "", "yakCat" => array(new MongoId($yakdicoYakCatId)), "creationDate" => new MongoDate(gmmktime()), "lastModifDate" => new MongoDate(gmmktime()), "location" => array("lat" => $geolocGMAP[0], "lng" => $geolocGMAP[1]), "status" => 1, "user" => 0, "zone" => 1, "address" => $addressGMAP);