Получение соседних улиц с перекрестка в номинате с PHPPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Получение соседних улиц с перекрестка в номинате с PHP

Сообщение 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/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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»