×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Сергей Шевченко
Added: Apr 21, 2017 10:08 AM
Modified: Mar 21, 2019 11:58 AM
Views: 2668
  1. /**
  2.  * Получение геоположение по адресу
  3.  * @var string $place Адрес ("Россия, Белгородская обл, г.Губкин, ул.Раевского, дом 3")
  4.  * @reurn array ['lat' => <float>, 'lng' => <float>]
  5.  */
  6. private function makeYandexApiRequest(string $place): array
  7.     {
  8.         $place['format'] = 'json';
  9.         $apiUrl = 'https://geocode-maps.yandex.ru/1.x/';
  10.         $apiUrl .= sprintf('?format=%s&geocode=%s', $place['format'], $place['address'];
  11.         //$context = stream_context_create(['http' => ['timeout' => 5]]);
  12.  
  13.         // Make request
  14.         for ($i = 1; $i <= 5; $i++) {
  15.             $response = json_decode(file_get_contents($apiUrl, false));
  16.  
  17.             if ($response) {
  18.                 break;
  19.             }
  20.  
  21.             if ($i === 5) {
  22.                 $date = new \DateTime();
  23.                 $error = sprintf(
  24.                     '%s Геокоординаты c Yandex не получены! Адресс: %s',
  25.                     $date->format('[Y-m-d H:i:s]'),
  26.                     $place['address']
  27.                 );
  28.                 file_put_contents('migrate_all.log', $error . "\n", FILE_APPEND);
  29.                 file_put_contents('migrate_errors.log', $error . "\n", FILE_APPEND);
  30.                 $this->stepErrorDot();
  31.                 $this->errorsList[] = $error;
  32.                 break;
  33.             }
  34.         }
  35.  
  36.         // Check response
  37.         if (isset($response->response->GeoObjectCollection->metaDataProperty->found) && 0 === $response->response->GeoObjectCollection->metaDataProperty->found) {
  38.             return null;
  39.         }
  40.  
  41.         if (!isset($response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos)) {
  42.             return null;
  43.         }
  44.         $point = explode(' ', $response->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos);
  45.  
  46.         $geoInfo = [
  47.             'lat' => $point[0],
  48.             'lng' => $point[1],
  49.         ];
  50.  
  51.         return $geoInfo;
  52.     }

3 comments

user84500 2 months ago
Are you looking for an nuru massage NY, sensual massage NY, exotic massage NY, tantric massage NY, adult massage NY or bodywork NY? Nuru Massage In Manhattan, NY were the first to offer arousing and slippery massage and we are dedicated to it for now. If you want the most sexually exciting massage service, look no further than the Nuru Massage In Manhattan, NY. Our parlour massage, erotic massage, body rub massage girls will pleasure you like no one before.
New-York erotic: [url=nuru-massage-ny.com/]massage oils[/url] best massage[/url]
user84500 2 months ago
Are you looking for an best massage NY, sensual massage NY, japanese massage NY, tantric massage NY, adult massage NY or body to body massage NY? Nuru Massage In Manhattan, NY were the first to offer inspiring and slippery massage and we are dedicated to it for now. If you want the most exotic massage parlour, look no further than the Nuru Elite. Our nuru massage, japanese massage, adult massage girls will pleasure you like no one before.
Nuru massage New-York: [url=nuru-massage-ny.com/]massage nj[/url] massage manhattan[/url]
user84500 2 months ago
Are you looking for an nuru massage NY, parlour massage NY, exotic massage NY, tantric massage NY, adult massage NY or bodywork NY? Nuru Massage In Manhattan, NY were the first to offer sensational and slippery massage and we are dedicated to it for now. If you want the most sexually exciting massage parlour, look no further than the Nuru Elite. Our best massage, happy ending massage, body rub massage girls will pleasure you like no one before.
Nuru Massage Erotic - [url=nuru-massage-ny.com/]massage brooklyn[/url] nude massage[/url]

Write a comment