woocommerce ve özel yazılım olarak bir çok yazılımları geliştiriyorum ve ücretli & ücretsiz paylaşımlarda bulunuyorum r10 da sürekli olarak ücretsiz paylaşımlarımı yapıyorum tamamen herkes faydalansın diye.
Bu paylaşacağım yazılım ham halidir sistem %100 çalışıyor fakat bu çalışmamın üstüne bir çok geliştirmeler yaptım ücretli apiler ve daha fazla bir çok özellik ekledim. Bu tür bir yazılım geliştirmek isteyen kişiler için sistem mantığını ham haliyle çalışır vaziyette paylaşıyorum :
index.php dosyamızı oluşturuyoruz yapmamız gereken tek şey tek bir dosyada harita önizleme vb alanlarını ücretsiz api olmadan kullanabilir olacaksınız :
<?php
// Türkiye'ye ait 81 ilin listesi (sadece örnek için bazı şehirler eklenmiştir; diğerlerini de ekleyebilirsiniz)
$cities = [
"Adana", "Adıyaman", "Afyonkarahisar", "Ağrı", "Aksaray", "Amasya", "Ankara", "Antalya",
"Artvin", "Aydın", "Balıkesir", "Bartın", "Batman", "Bayburt", "Bilecik", "Bingöl", "Bitlis",
"Bolu", "Burdur", "Bursa", "Çanakkale", "Çankırı", "Çorum", "Denizli", "Diyarbakır", "Düzce",
"Edirne", "Elazığ", "Erzincan", "Erzurum", "Eskişehir", "Gaziantep", "Giresun", "Gümüşhane",
"Hakkâri", "Hatay", "Iğdır", "Isparta", "İstanbul", "İzmir", "Kahramanmaraş", "Karabük", "Karaman",
"Kastamonu", "Kayseri", "Kırıkkale", "Kırklareli", "Kırşehir", "Kocaeli", "Konya", "Kütahya", "Malatya",
"Manisa", "Mardin", "Mersin", "Muğla", "Muş", "Nevşehir", "Niğde", "Ordu", "Osmaniye", "Rize", "Sakarya",
"Samsun", "Siirt", "Sinop", "Sivas", "Şanlıurfa", "Şırnak", "Tekirdağ", "Tokat", "Trabzon", "Tunceli",
"Uşak", "Van", "Yalova", "Yozgat", "Zonguldak"
];
sort($cities);
// Statik koordinat, veritabanı bağlantısı yapabilirsiniz
// Değerlerin formatı: "Şehir, Turkey" => [ "lat" => ..., "lon" => ... ]
$staticCityCoordinates = [
"Adana, Turkey" => [ "lat" => 36.9914, "lon" => 35.3308 ],
"Adıyaman, Turkey" => [ "lat" => 37.7648, "lon" => 38.2786 ],
"Afyonkarahisar, Turkey" => [ "lat" => 38.7567, "lon" => 30.5563 ],
"Ağrı, Turkey" => [ "lat" => 39.7191, "lon" => 43.0509 ],
"Aksaray, Turkey" => [ "lat" => 38.3703, "lon" => 34.0370 ],
"Amasya, Turkey" => [ "lat" => 40.6532, "lon" => 35.8354 ],
"Ankara, Turkey" => [ "lat" => 39.9208, "lon" => 32.8541 ],
"Antalya, Turkey" => [ "lat" => 36.8841, "lon" => 30.7056 ],
"Artvin, Turkey" => [ "lat" => 41.1828, "lon" => 41.8184 ],
"Aydın, Turkey" => [ "lat" => 37.8600, "lon" => 27.8427 ],
"Balıkesir, Turkey" => [ "lat" => 39.6492, "lon" => 27.8824 ],
"Bartın, Turkey" => [ "lat" => 41.6353, "lon" => 32.3376 ],
"Batman, Turkey" => [ "lat" => 37.8894, "lon" => 41.1323 ],
"Bayburt, Turkey" => [ "lat" => 40.2555, "lon" => 40.2270 ],
"Bilecik, Turkey" => [ "lat" => 40.1448, "lon" => 29.9797 ],
"Bingöl, Turkey" => [ "lat" => 38.8834, "lon" => 40.4841 ],
"Bitlis, Turkey" => [ "lat" => 38.4961, "lon" => 42.1143 ],
"Bolu, Turkey" => [ "lat" => 40.7340, "lon" => 31.6094 ],
"Burdur, Turkey" => [ "lat" => 37.4692, "lon" => 30.0661 ],
"Bursa, Turkey" => [ "lat" => 40.1828, "lon" => 29.0665 ],
"Çanakkale, Turkey" => [ "lat" => 40.1583, "lon" => 26.4142 ],
"Çankırı, Turkey" => [ "lat" => 40.6010, "lon" => 33.6173 ],
"Çorum, Turkey" => [ "lat" => 40.5497, "lon" => 34.9555 ],
"Denizli, Turkey" => [ "lat" => 37.7748, "lon" => 29.8381 ],
"Diyarbakır, Turkey" => [ "lat" => 37.9103, "lon" => 40.2306 ],
"Düzce, Turkey" => [ "lat" => 40.8419, "lon" => 31.1596 ],
"Edirne, Turkey" => [ "lat" => 41.6764, "lon" => 26.5569 ],
"Elazığ, Turkey" => [ "lat" => 38.6811, "lon" => 39.2232 ],
"Erzincan, Turkey" => [ "lat" => 39.7527, "lon" => 39.7545 ],
"Erzurum, Turkey" => [ "lat" => 39.9334, "lon" => 41.2674 ],
"Eskişehir, Turkey" => [ "lat" => 39.7767, "lon" => 30.5206 ],
"Gaziantep, Turkey" => [ "lat" => 37.0662, "lon" => 37.3833 ],
"Giresun, Turkey" => [ "lat" => 40.9124, "lon" => 38.3891 ],
"Gümüşhane, Turkey" => [ "lat" => 40.4586, "lon" => 39.4857 ],
"Hakkâri, Turkey" => [ "lat" => 37.5711, "lon" => 43.7352 ],
"Hatay, Turkey" => [ "lat" => 36.3632, "lon" => 36.3197 ],
"Iğdır, Turkey" => [ "lat" => 40.3839, "lon" => 44.0364 ],
"Isparta, Turkey" => [ "lat" => 37.7491, "lon" => 30.5552 ],
"İstanbul, Turkey" => [ "lat" => 41.0082, "lon" => 28.9784 ],
"İzmir, Turkey" => [ "lat" => 38.4237, "lon" => 27.1428 ],
"Kahramanmaraş, Turkey" => [ "lat" => 37.5735, "lon" => 36.9376 ],
"Karabük, Turkey" => [ "lat" => 41.2085, "lon" => 32.6211 ],
"Karaman, Turkey" => [ "lat" => 37.1754, "lon" => 33.2257 ],
"Kastamonu, Turkey" => [ "lat" => 41.9890, "lon" => 33.7836 ],
"Kayseri, Turkey" => [ "lat" => 38.7223, "lon" => 35.4875 ],
"Kırıkkale, Turkey" => [ "lat" => 39.8403, "lon" => 33.5145 ],
"Kırklareli, Turkey" => [ "lat" => 41.7365, "lon" => 27.2250 ],
"Kırşehir, Turkey" => [ "lat" => 39.1441, "lon" => 34.1706 ],
"Kocaeli, Turkey" => [ "lat" => 40.9833, "lon" => 29.8814 ],
"Konya, Turkey" => [ "lat" => 37.8746, "lon" => 32.4848 ],
"Kütahya, Turkey" => [ "lat" => 39.4194, "lon" => 29.9781 ],
"Malatya, Turkey" => [ "lat" => 38.3550, "lon" => 38.3092 ],
"Manisa, Turkey" => [ "lat" => 38.4654, "lon" => 27.1287 ],
"Mardin, Turkey" => [ "lat" => 37.3148, "lon" => 40.7396 ],
"Mersin, Turkey" => [ "lat" => 36.8013, "lon" => 34.6401 ],
"Muğla, Turkey" => [ "lat" => 37.2148, "lon" => 28.3645 ],
"Muş, Turkey" => [ "lat" => 38.7434, "lon" => 41.8197 ],
"Nevşehir, Turkey" => [ "lat" => 38.6249, "lon" => 34.6865 ],
"Niğde, Turkey" => [ "lat" => 37.9660, "lon" => 34.6781 ],
"Ordu, Turkey" => [ "lat" => 40.9833, "lon" => 37.8766 ],
"Osmaniye, Turkey" => [ "lat" => 37.0731, "lon" => 36.2495 ],
"Rize, Turkey" => [ "lat" => 41.0217, "lon" => 40.5175 ],
"Sakarya, Turkey" => [ "lat" => 40.7682, "lon" => 30.4400 ],
"Samsun, Turkey" => [ "lat" => 41.2867, "lon" => 36.33 ],
"Siirt, Turkey" => [ "lat" => 37.9335, "lon" => 41.9396 ],
"Sinop, Turkey" => [ "lat" => 42.0050, "lon" => 35.1458 ],
"Sivas, Turkey" => [ "lat" => 39.7477, "lon" => 37.0179 ],
"Şanlıurfa, Turkey" => [ "lat" => 37.1591, "lon" => 38.7969 ],
"Şırnak, Turkey" => [ "lat" => 37.5142, "lon" => 42.4571 ],
"Tekirdağ, Turkey" => [ "lat" => 40.9754, "lon" => 27.5126 ],
"Tokat, Turkey" => [ "lat" => 40.3161, "lon" => 36.5561 ],
"Trabzon, Turkey" => [ "lat" => 41.0019, "lon" => 39.7168 ],
"Tunceli, Turkey" => [ "lat" => 39.1151, "lon" => 39.5470 ],
"Uşak, Turkey" => [ "lat" => 38.6833, "lon" => 29.4087 ],
"Van, Turkey" => [ "lat" => 38.2982, "lon" => 43.4107 ],
"Yalova, Turkey" => [ "lat" => 40.6507, "lon" => 29.2771 ],
"Yozgat, Turkey" => [ "lat" => 39.8187, "lon" => 34.8047 ],
"Zonguldak, Turkey" => [ "lat" => 41.4517, "lon" => 31.7982 ]
];
$result = null;
$routeGeometry = null;
$city1_coords = null;
$city2_coords = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$city1 = $_POST['city1'];
$city2 = $_POST['city2'];
$consumption = floatval($_POST['consumption']);
$fuelPrice = floatval($_POST['fuelPrice']);
$city1_coords = getCoordinates($city1);
$city2_coords = getCoordinates($city2);
if (!$city1_coords || !$city2_coords) {
$result = "Koordinatlar alınamadı. Lütfen şehir isimlerini kontrol ediniz.";
} else {
$route = getRoute($city1_coords, $city2_coords);
if (!$route) {
$result = "Rota bilgileri alınamadı.";
} else {
$distanceKm = $route['distance'] / 1000;
$durationSec = $route['duration'];
$durationHrs = $durationSec / 3600;
$fuelNeeded = ($distanceKm / 100) * $consumption;
$fuelCost = $fuelNeeded * $fuelPrice;
$result = [
'city1' => $city1,
'city2' => $city2,
'distanceKm' => $distanceKm,
'durationHrs' => $durationHrs,
'fuelNeeded' => $fuelNeeded,
'fuelCost' => $fuelCost
];
if (isset($route['geometry'])) {
$routeGeometry = $route['geometry'];
}
}
}
}
function getCoordinates($cityName) {
global $staticCityCoordinates;
if (isset($staticCityCoordinates[$cityName])) {
return $staticCityCoordinates[$cityName];
}
return false;
}
function getRoute($coord1, $coord2) {
$url = "http://router.project-osrm.org/route/v1/driving/{$coord1['lon']},{$coord1['lat']};{$coord2['lon']},{$coord2['lat']}?overview=full&geometries=geojson";
$json = file_get_contents($url);
if ($json === false) {
return false;
}
$data = json_decode($json, true);
if ($data && isset($data['routes'][0])) {
return $data['routes'][0];
}
return false;
}
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>Rota ve Yakıt Hesaplama</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
label { display: inline-block; width: 200px; }
select, input[type="text"] { width: 220px; }
#map { height: 400px; width: 100%; margin-top: 20px; }
</style>
</head>
<body>
<h1>Rota ve Yakıt Hesaplama</h1>
<form method="post">
<p>
<label for="city1">Başlangıç Şehri:</label>
<select name="city1" id="city1" required>
<?php
foreach($cities as $city):
$value = $city . ", Turkey";
$selected = (isset($_POST['city1']) && $_POST['city1'] == $value) ? 'selected' : '';
?>
<option value="<?php echo htmlspecialchars($value); ?>" <?php echo $selected; ?>>
<?php echo htmlspecialchars($city); ?>
</option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="city2">Bitiş Şehri:</label>
<select name="city2" id="city2" required>
<?php
foreach($cities as $city):
$value = $city . ", Turkey";
$selected = (isset($_POST['city2']) && $_POST['city2'] == $value) ? 'selected' : '';
?>
<option value="<?php echo htmlspecialchars($value); ?>" <?php echo $selected; ?>>
<?php echo htmlspecialchars($city); ?>
</option>
<?php endforeach; ?>
</select>
</p>
<p>
<label for="consumption">Yakıt Tüketimi (L/100km):</label>
<input type="text" name="consumption" id="consumption" value="<?php echo isset($_POST['consumption']) ? htmlspecialchars($_POST['consumption']) : '7.5'; ?>" required>
</p>
<p>
<label for="fuelPrice">Yakıt Fiyatı (TL/Litre):</label>
<input type="text" name="fuelPrice" id="fuelPrice" value="<?php echo isset($_POST['fuelPrice']) ? htmlspecialchars($_POST['fuelPrice']) : '7.0'; ?>" required>
</p>
<p>
<input type="submit" value="Hesapla">
</p>
</form>
<?php if ($result): ?>
<?php if (is_string($result)): ?>
<p><?php echo $result; ?></p>
<?php else: ?>
<h2>Rota ve Yakıt Bilgileri</h2>
<p>
Başlangıç Şehri: <strong><?php echo htmlspecialchars($result['city1']); ?></strong><br>
Bitiş Şehri: <strong><?php echo htmlspecialchars($result['city2']); ?></strong>
</p>
<p>
Toplam Mesafe: <strong><?php echo number_format($result['distanceKm'], 2); ?> km</strong><br>
Tahmini Süre: <strong><?php echo number_format($result['durationHrs'], 2); ?> saat</strong><br>
Tahmini Yakıt Tüketimi: <strong><?php echo number_format($result['fuelNeeded'], 2); ?> litre</strong><br>
Yakıt Maliyeti: <strong><?php echo number_format($result['fuelCost'], 2); ?> TL</strong>
</p>
<?php if ($routeGeometry && $city1_coords && $city2_coords): ?>
<div id="map"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
var map = L.map('map');
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
var routeGeometry = <?php echo json_encode($routeGeometry); ?>;
var routeLayer = L.geoJSON(routeGeometry, {
style: { color: 'blue', weight: 4 }
}).addTo(map);
map.fitBounds(routeLayer.getBounds());
var startCoords = [<?php echo $city1_coords['lat']; ?>, <?php echo $city1_coords['lon']; ?>];
var endCoords = [<?php echo $city2_coords['lat']; ?>, <?php echo $city2_coords['lon']; ?>];
L.marker(startCoords, {
icon: L.icon({
iconUrl: 'https://cdn-icons-png.flaticon.com/512/252/252025.png',
iconSize: [25, 41],
iconAnchor: [12, 41]
})
})
.addTo(map)
.bindPopup("Başlangıç: <?php echo htmlspecialchars($result['city1']); ?>")
.openPopup();
L.marker(endCoords, {
icon: L.icon({
iconUrl: 'https://cdn-icons-png.flaticon.com/512/252/252035.png',
iconSize: [25, 41],
iconAnchor: [12, 41]
})
})
.addTo(map)
.bindPopup("Bitiş: <?php echo htmlspecialchars($result['city2']); ?>");
</script>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</body>
</html>
