Police Station is not a place where we visit regularly, until and unless there is something wrong or you are connected with the department in any ways, however if you want to know where the police station within the 10kms radius, then you have got into the right place.
This webpage has the two options, wherein the system can detect your location and provide the details and how far it's from current location or you can enter the location and then system will provide you the list of information.
Find the Nearest Police Station
...
var lng = data[0].lon;
searchAutoStands(lat, lng);
} else {
alert("Location not found. Please enter a valid address.");
}
});
}
// Common function to search for auto-rickshaw stands based on latitude and longitude
function searchAutoStands(lat, lng) {
var userLocation = [lat, lng];
// Set the map view to the specified location
map.setView(userLocation, 15);
// Place a marker at the specified location
L.marker(userLocation).addTo(map).bindPopup("Search Location").openPopup();
// Query Overpass API for nearest auto-rickshaw stands
var overpassUrl = "https://overpass-api.de/api/interpreter";
var query = `
[out:json];
node
["amenity"="police"]
(around:10000,${lat},${lng});
out;
`;
$.get(overpassUrl, { data: query }, function (data) {
var results = data.elements;
if (results.length > 0) {
displayResults(results, userLocation);
} else {
alert("No police station found nearby.");
}
});
}
function displayResults(results, userLocation) {
var table = '';
results.forEach(function (place) {
var placeLocation = [place.lat, place.lon];
var distance = (calculateDistance(userLocation, placeLocation) / 1000).toFixed(2); // Convert to km
// Add a marker for each auto stand
L.marker(placeLocation).addTo(map).bindPopup(place.tags.name || "Unnamed Auto Stand");
table += ``;
});
table += '
';
$('#divTable').html(table);
}
// Function to calculate the distance between two lat/lng points in meters
function calculateDistance(coords1, coords2) {
var R = 6371e3; // Earth radius in meters
var lat1 = coords1[0] * Math.PI / 180;
var lat2 = coords2[0] * Math.PI / 180;
var deltaLat = (coords2[0] - coords1[0]) * Math.PI / 180;
var deltaLng = (coords2[1] - coords1[1]) * Math.PI / 180;
var a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
Math.cos(lat1) * Math.cos(lat2) *
Math.sin(deltaLng / 2) * Math.sin(deltaLng / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c; // Distance in meters
}
]]>
Name | Distance (km) |
---|---|
${place.tags.name || 'Unnamed Police Station'} | ${distance} |
0 Response to "Police Station Near Me"
Post a Comment