From 4e08b64a0114b5d99ffc7b2357e3ed68e6faaa06 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sun, 6 Sep 2015 23:09:08 +0300 Subject: [PATCH] =?UTF-8?q?ADD=20=D0=B3=D0=B5=D0=BE-=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B7=20Google;=20FIX=20=D0=BF=D0=BE=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=20=D0=BF=D0=BE=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=D0=B0=D1=82=D0=B0=D0=BC=20=D0=B2=20=D0=AF=D0=BD=D0=B4?= =?UTF-8?q?=D0=B5=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/JsonController.php | 43 +++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 425ce2b..6d51054 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -94,7 +94,7 @@ class JsonController extends Controller */ static function actionCategories() { - $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true, 'asArrayOf' => true)); + $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true, 'noKeys' => true)); self::renderPartial('json.php', array( 'data' => $categories, @@ -372,6 +372,39 @@ class JsonController extends Controller $lng = $coords[0]; $results[] = array('value' => $name, 'data' => "/?lat=$lat&lng=$lng&zoom=13"); } + } else if (isset($obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->Point)) { + $coords = explode(' ', (string) $obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->Point->pos); + $lat = $coords[1]; + $lng = $coords[0]; + $name = "Координаты N°" . $lat . ' E°' . $lng; + $results[] = array('value' => $name, 'data' => "/?lat=$lat&lng=$lng&zoom=13"); + } + } + } + curl_close($ch); + } + + if (count($results) < 10 && strlen($search) > 5) { + // ====== GOOGLE ============ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://maps.googleapis.com/maps/api/geocode/json?language=ru&key=AIzaSyDuWmguxO35oV9WGc6D8xUPvQBaUS4kt78&address=' . urlencode($search)); + curl_setopt($ch, CURLOPT_TIMEOUT, 3); + curl_setopt($ch, CURLOPT_REFERER, "http://wikipoints.ru"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $out = null; + $out = curl_exec($ch); + + if (!empty($out)) { + $obj = json_decode($out); + if ((string) $obj->status == 'OK') { + $count = count($obj->results); + if ($count > 0) { + for ($index = 0; $index < $count && $index < 5 && count($results) < 25; $index++) { + $name = (string) $obj->results[$index]->formatted_address; + $lat = (string) $obj->results[$index]->geometry->location->lat; + $lng = (string) $obj->results[$index]->geometry->location->lng; + $results[] = array('value' => $name, 'data' => "/?lat=$lat&lng=$lng&zoom=13"); + } } } } @@ -423,12 +456,12 @@ class JsonController extends Controller self::renderPartial('json.php', array( 'data' => ArticlePhotos::model()->getAll( array( - 'where'=>'`owner` = '.(int) App::$user->id, + 'where' => '`owner` = ' . (int) App::$user->id, 'order' => '`id` DESC', - 'asArray'=>true, - 'noKeys'=>true - ) + 'asArray' => true, + 'noKeys' => true ) + ) )); }