32 lines
1.0 KiB
PHP
32 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config_ajax.php");
|
||
|
|
|
||
|
|
/*ini_set('display_errors', 1);
|
||
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);*/
|
||
|
|
|
||
|
|
if($_POST['address']) {
|
||
|
|
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
|
||
|
|
$yaParams['geocode'] = $post['address'];
|
||
|
|
$yaParams['format'] = 'json';
|
||
|
|
$yaParams['results'] = "1";
|
||
|
|
$yaParams['apikey'] = "898fc684-cdf6-4af8-af57-15e2781d68d1";
|
||
|
|
|
||
|
|
$yaUrlParams = http_build_query($yaParams);
|
||
|
|
|
||
|
|
$url = "https://geocode-maps.yandex.ru/1.x/?" . $yaUrlParams;
|
||
|
|
|
||
|
|
$json = file_get_contents($url);
|
||
|
|
$json = json_decode($json, true);
|
||
|
|
|
||
|
|
if ($json['response'] && $json['response']['GeoObjectCollection'] &&
|
||
|
|
$json['response']['GeoObjectCollection']['featureMember'] && $json['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']) {
|
||
|
|
|
||
|
|
$geoObj = $json['response']['GeoObjectCollection']['featureMember'][0]['GeoObject'];
|
||
|
|
|
||
|
|
if ($geoObj['Point'] && $geoObj['Point']['pos']) {
|
||
|
|
echo "success:" . $geoObj['Point']['pos'];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|