Я не могу получить возвращенные результаты 2 улиц в каждом направлении от пересечения. Br /> Необходим выход:
North 1: 11th St
North 2: 10th ST
South 1: 12th ST
South 2: 13th St
East 1: 7th Ave
East 2: 8th Ave
West 1: 5th Ave
West 2: 4th Ave < /p>
Вот мой код ниже, который есть некоторые данные отладки i Собран в сценарии: < /p>
`// Function to sanitize intersection names
function sanitizeIntersection($intersection) {
$intersection = str_replace(" and ", ", ", $intersection); // Replace "and" with a comma
$intersection = trim($intersection);
// Append city and state for better geocoding
$city = "Sioux Falls";
$state = "SD";
return "$intersection, $city, $state";
}
// Function to fetch geocoding data using cURL
function geocodeIntersection($intersection) {
$url = "https://nominatim.openstreetmap.org/search?q=" . urlencode($intersection) . "&format=json&limit=1";
global $debugLog; // Capture the URL being used
addToDebugLog("Geocoding URL: $url");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"User-Agent: RedObsidianSecurity/1.0 (admin@redobsidiansecurity.com)"
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
addToDebugLog("cURL error: " . curl_error($ch));
return null;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
addToDebugLog("HTTP error: $httpCode for $intersection");
return null;
}
curl_close($ch);
$data = json_decode($response, true);
if (isset($data[0])) {
return [
"lat" => $data[0]["lat"],
"lon" => $data[0]["lon"]
];
} else {
addToDebugLog("No geocoding results found for $intersection");
}
return null;
}
// Function to get two nearby streets in a given direction
function getNearbyStreets($lat, $lon, $direction) {
$offset = 0.001; // Approx 100m offset
$streets = [];
// First street
$lat1 = $lat;
$lon1 = $lon;
switch ($direction) {
case 'N': $lat1 += $offset; break;
case 'S': $lat1 -= $offset; break;
case 'E': $lon1 += $offset; break;
case 'W': $lon1 -= $offset; break;
}
$streets[] = reverseGeocode($lat1, $lon1);
// Second street
$lat2 = $lat1;
$lon2 = $lon1;
switch ($direction) {
case 'N': $lat2 += $offset; break;
case 'S': $lat2 -= $offset; break;
case 'E': $lon2 += $offset; break;
case 'W': $lon2 -= $offset; break;
}
$streets[] = reverseGeocode($lat2, $lon2);
return $streets;
}
// Function to perform reverse geocoding
function reverseGeocode($lat, $lon) {
$url = "https://nominatim.openstreetmap.org/rev ... on&zoom=17";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"User-Agent: RedObsidianSecurity/1.0 (admin@redobsidiansecurity.com)"
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
addToDebugLog("cURL error: " . curl_error($ch));
return "Unknown";
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
addToDebugLog("HTTP error: $httpCode for lat: $lat, lon: $lon");
return "Unknown";
}
curl_close($ch);
$data = json_decode($response, true);
return $data['address']['road'] ?? "Unknown";
}
Debug Info:
Running query:
SELECT id, ClosestIntersection, IncidentNumber
FROM Incident
WHERE id NOT IN (SELECT pkid FROM nearbystreets)
LIMIT 10
Processing Intersection: , Sioux Falls, SD (IncidentID: XXXXXXX)
Geocoding URL: https://nominatim.openstreetmap.org/sea ... on&limit=1
Coordinates: Lat 43.5476008, Lon -96.7293629
Successfully inserted record for pkid: 1, IncidentID: XXXXXXX.
Processing Intersection: S MARION RD, W ST JAMES DR, Sioux Falls, SD (IncidentID: XXXXXXX)
Geocoding URL: https://nominatim.openstreetmap.org/sea ... on&limit=1
No geocoding results found for S MARION RD, W ST JAMES DR, Sioux Falls, SD
Failed to geocode intersection: S MARION RD, W ST JAMES DR, Sioux Falls, SD
Processing Intersection: W RUSSELL ST, N WEST AVE, Sioux Falls, SD (IncidentID: CFS25-017102)
Geocoding URL: https://nominatim.openstreetmap.org/sea ... on&limit=1`
Подробнее здесь: https://stackoverflow.com/questions/793 ... m-with-php
Получение соседних улиц с перекрестка в номинате с PHP ⇐ Php
Кемеровские программисты php общаются здесь
-
Anonymous
1738137154
Anonymous
Я не могу получить возвращенные результаты 2 улиц в каждом направлении от пересечения. Br /> Необходим выход:
North 1: 11th St
North 2: 10th ST
South 1: 12th ST
South 2: 13th St
East 1: 7th Ave
East 2: 8th Ave
West 1: 5th Ave
West 2: 4th Ave < /p>
Вот мой код ниже, который есть некоторые данные отладки i Собран в сценарии: < /p>
`// Function to sanitize intersection names
function sanitizeIntersection($intersection) {
$intersection = str_replace(" and ", ", ", $intersection); // Replace "and" with a comma
$intersection = trim($intersection);
// Append city and state for better geocoding
$city = "Sioux Falls";
$state = "SD";
return "$intersection, $city, $state";
}
// Function to fetch geocoding data using cURL
function geocodeIntersection($intersection) {
$url = "https://nominatim.openstreetmap.org/search?q=" . urlencode($intersection) . "&format=json&limit=1";
global $debugLog; // Capture the URL being used
addToDebugLog("Geocoding URL: $url");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"User-Agent: RedObsidianSecurity/1.0 (admin@redobsidiansecurity.com)"
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
addToDebugLog("cURL error: " . curl_error($ch));
return null;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
addToDebugLog("HTTP error: $httpCode for $intersection");
return null;
}
curl_close($ch);
$data = json_decode($response, true);
if (isset($data[0])) {
return [
"lat" => $data[0]["lat"],
"lon" => $data[0]["lon"]
];
} else {
addToDebugLog("No geocoding results found for $intersection");
}
return null;
}
// Function to get two nearby streets in a given direction
function getNearbyStreets($lat, $lon, $direction) {
$offset = 0.001; // Approx 100m offset
$streets = [];
// First street
$lat1 = $lat;
$lon1 = $lon;
switch ($direction) {
case 'N': $lat1 += $offset; break;
case 'S': $lat1 -= $offset; break;
case 'E': $lon1 += $offset; break;
case 'W': $lon1 -= $offset; break;
}
$streets[] = reverseGeocode($lat1, $lon1);
// Second street
$lat2 = $lat1;
$lon2 = $lon1;
switch ($direction) {
case 'N': $lat2 += $offset; break;
case 'S': $lat2 -= $offset; break;
case 'E': $lon2 += $offset; break;
case 'W': $lon2 -= $offset; break;
}
$streets[] = reverseGeocode($lat2, $lon2);
return $streets;
}
// Function to perform reverse geocoding
function reverseGeocode($lat, $lon) {
$url = "https://nominatim.openstreetmap.org/reverse?format=json&lat=$lat&lon=$lon&zoom=17";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"User-Agent: RedObsidianSecurity/1.0 (admin@redobsidiansecurity.com)"
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
addToDebugLog("cURL error: " . curl_error($ch));
return "Unknown";
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
addToDebugLog("HTTP error: $httpCode for lat: $lat, lon: $lon");
return "Unknown";
}
curl_close($ch);
$data = json_decode($response, true);
return $data['address']['road'] ?? "Unknown";
}
Debug Info:
Running query:
SELECT id, ClosestIntersection, IncidentNumber
FROM Incident
WHERE id NOT IN (SELECT pkid FROM nearbystreets)
LIMIT 10
Processing Intersection: , Sioux Falls, SD (IncidentID: XXXXXXX)
Geocoding URL: https://nominatim.openstreetmap.org/search?q=%2C+Sioux+Falls%2C+SD&format=json&limit=1
Coordinates: Lat 43.5476008, Lon -96.7293629
Successfully inserted record for pkid: 1, IncidentID: XXXXXXX.
Processing Intersection: S MARION RD, W ST JAMES DR, Sioux Falls, SD (IncidentID: XXXXXXX)
Geocoding URL: https://nominatim.openstreetmap.org/search?q=S+MARION+RD%2C+W+ST+JAMES+DR%2C+Sioux+Falls%2C+SD&format=json&limit=1
No geocoding results found for S MARION RD, W ST JAMES DR, Sioux Falls, SD
Failed to geocode intersection: S MARION RD, W ST JAMES DR, Sioux Falls, SD
Processing Intersection: W RUSSELL ST, N WEST AVE, Sioux Falls, SD (IncidentID: CFS25-017102)
Geocoding URL: https://nominatim.openstreetmap.org/search?q=W+RUSSELL+ST%2C+N+WEST+AVE%2C+Sioux+Falls%2C+SD&format=json&limit=1`
Подробнее здесь: [url]https://stackoverflow.com/questions/79394850/retrieving-neighboring-streets-from-an-intersection-in-nominatim-with-php[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия