Answer the question
In order to leave comments, you need to log in
Why is GeoCoder Yandex MAPS API not correctly detecting address coordinates by feature name?
Hi everyone, I'm using GeoCoder to locate coordinates by school name. The problem is that GeoCoder detects extremely incorrect object coordinates on the map.
An example is the name of an educational organization KGB POU SIEK, I find the coordinates through the geocoder I get 47.141453 29.23.241
If we enter the name of the educational institution in the same Yandex maps, then we can easily find it, and if we enter the coordinates, we will get a wasteland in Moldova. Yes, and the coordinates are not confused, if you check the other way around, then we will get to the Arabs
29.23.241 47.141453
I also tried to specify the City + Name of the educational institution, similarly. That is, the example
of Spassk-Dalniy KGB POU SIEK
What is the reason for this? How to treat it? The code through which I request is attached.
<?php
$mysqli = new mysqli("localhost", "USER", "PASSWORD", "NAMEDB");
if ($mysqli->connect_errno) {
echo "Не удалось подключиться к MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
// Выборка данных из таблицы
$addresses = $mysqli->query("SELECT DISTINCT sid, name, value FROM webform_submission_data WHERE name = 'form_name_org'");
// Общее количество адресов и количество адресов, в обработке которых произошла ошибка
$countGeocode = $countGeocodeFault = 0;
// Обработка адресов
$result = '<table style="width:600px">';
while ($row = $addresses->fetch_assoc()) {
$countGeocode++;
// Обращение к http-геокодеру
$xml = simplexml_load_file('https://geocode-maps.yandex.ru/1.x/?apikey=API-KEY&geocode='.urlencode($row["value"]).'&results=1');
// Если геокодировать удалось, то записываем в БД
$found = $xml->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found;
if ($found > 0) {
$coords = explode(' ', $xml->GeoObjectCollection->featureMember->GeoObject->Point->pos);
$result .= '<tr><td>'.$row['value'].'</td><td>'.$coords.'</td></tr>';
$mysqli->query("UPDATE webform_submission_data SET lon = '".$mysqli->real_escape_string($coords[1])."', lat = '".$mysqli->real_escape_string($coords[0])."' WHERE sid = {$row['sid']} AND name = 'form_name_org'");
}
else {
$result .= '<tr style="color:red"><td>'.$row['value'].'</td><td>ошибка</td></tr>';
$countGeocodeFault++;
}
};
$result .= '</table>';
// Вывод результата
echo $result;
// Закрытие соеденинения с сервером
mysqli_close($mysqli);
// Вывод общего количество прогеокодированных результатов
if ($countGeocode) {
echo '<div style="margin-top:1em">Всего обработано адресов: '.$countGeocode.'</div>';
if ($countGeocodeFault) {
echo '<div style="color:red">Не удалось прогеокодировать: '.$countGeocodeFault.'</div>';
}
} else {
echo '<div>Таблица с адресами пуста.</div>';
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question