FIX 2 - geo coding

This commit is contained in:
Krivchikov Dmitry 2016-02-28 14:31:20 +03:00
parent 310b5a64bb
commit 8383af2730
1 changed files with 31 additions and 32 deletions

View File

@ -365,38 +365,37 @@ class JsonController extends Controller
static function actionGeoCoding()
{
// ====== GOOGLE ============
// $lat = $lng = FALSE;
// $search = isset($_GET['search']) ? $_GET['search'] : '';
//
// $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 = curl_exec($ch);
//App::log('geoCoding', $out);
//
// if (!empty($out)) {
// $obj = json_decode($out);
// if ((string) $obj->status == 'OK') {
// $count = count($obj->results);
// if ($count > 0) {
// $index = 0;
// $name = (string) $obj->results[$index]->formatted_address;
// $lat = (string) $obj->results[$index]->geometry->location->lat;
// $lng = (string) $obj->results[$index]->geometry->location->lng;
// }
// }
// }
// curl_close($ch);
//
// $coords = array();
// $coords['lat'] = $lat;
// $coords['lng'] = $lng;
//
// self::renderPartial('json.php', $coords);
//
// die;
$lat = $lng = FALSE;
$search = isset($_GET['search']) ? $_GET['search'] : '';
$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 = curl_exec($ch);
if (!empty($out)) {
$obj = json_decode($out);
if ((string) $obj->status == 'OK') {
$count = count($obj->results);
if ($count > 0) {
$index = 0;
$name = (string) $obj->results[$index]->formatted_address;
$lat = (string) $obj->results[$index]->geometry->location->lat;
$lng = (string) $obj->results[$index]->geometry->location->lng;
$coords = array();
$coords['lat'] = $lat;
$coords['lng'] = $lng;
self::renderPartial('json.php', $coords);
die;
}
}
}
curl_close($ch);
// ========== YANDEX =============
$address = isset($_GET['search']) ? $_GET['search'] : '';