Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latitude Longitude ile sehir kontrolu eklendi #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/LocationAdd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Input } from './Input.jsx';
import { Label } from './Label.jsx';
import { Select } from './Select.jsx';
import { subTypeOptions, typeOptions } from './TypeOptions.jsx';
import { verifyLatLong } from '../utils';

export function LocationAdd({ refresh }) {
const { data, post, response, loading, get } = useFetch('/location');
Expand Down Expand Up @@ -64,8 +65,11 @@ export function LocationAdd({ refresh }) {
...formData,
});


let selectedCityData = cityData.find(o => o.id === formData.cityId);
let verifyLocation = verifyLatLong(selectedCityData.lat, selectedCityData.long, formData.latitude, formData.longitude, 10);
if (response.ok) {
if (newLocation.data) {
if (newLocation.data && verifyLocation) {
console.log('New location added');

setFormData(initialFormData);
Expand Down
20 changes: 20 additions & 0 deletions src/datasets/cityData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"id": 1,
"key": "Adana",
"lat": "37.00801",
"long": "35.33281",
"districts": [
{ "id": 1, "key": "Yüreğir" },
{ "id": 2, "key": "Yumurtalık" },
Expand All @@ -23,6 +25,8 @@
{
"id": 2,
"key": "Adıyaman",
"lat": "37.764542",
"long": "38.276451",
"districts": [
{ "id": 16, "key": "Tut" },
{ "id": 17, "key": "Sincik" },
Expand All @@ -38,6 +42,8 @@
{
"id": 21,
"key": "Diyarbakır",
"lat": "37.916248",
"long": "40.225590",
"districts": [
{ "id": 261, "key": "Yenişehir" },
{ "id": 262, "key": "Sur" },
Expand All @@ -61,6 +67,8 @@
{
"id": 27,
"key": "Gaziantep",
"lat": "37.065842",
"long": "37.376080",
"districts": [
{ "id": 338, "key": "Yavuzeli" },
{ "id": 339, "key": "Şehitkamil" },
Expand All @@ -76,6 +84,8 @@
{
"id": 31,
"key": "Hatay",
"lat": "36.202736",
"long": "36.16031",
"districts": [
{ "id": 374, "key": "Yayladağı" },
{ "id": 375, "key": "Samandağ" },
Expand All @@ -97,6 +107,8 @@
{
"id": 44,
"key": "Malatya",
"lat": "38.3477067",
"long": "38.2943099",
"districts": [
{ "id": 599, "key": "Yeşilyurt" },
{ "id": 600, "key": "Yazıhan" },
Expand All @@ -116,6 +128,8 @@
{
"id": 46,
"key": "Kahramanmaraş",
"lat": "37.5767418",
"long": "36.926527",
"districts": [
{ "id": 629, "key": "Türkoğlu" },
{ "id": 630, "key": "Pazarcık" },
Expand All @@ -133,6 +147,8 @@
{
"id": 63,
"key": "Şanlıurfa",
"lat": "37.1606037",
"long": "38.8004359",
"districts": [
{ "id": 827, "key": "Viranşehir" },
{ "id": 828, "key": "Suruç" },
Expand All @@ -152,6 +168,8 @@
{
"id": 79,
"key": "Kilis",
"lat": "36.7155317",
"long": "37.1136492",
"districts": [
{ "id": 944, "key": "Polateli" },
{ "id": 945, "key": "Musabeyli" },
Expand All @@ -162,6 +180,8 @@
{
"id": 80,
"key": "Osmaniye",
"lat": "37.0670071",
"long": "36.2323057",
"districts": [
{ "id": 948, "key": "Toprakkale" },
{ "id": 949, "key": "Sumbas" },
Expand Down
18 changes: 17 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
export const getDateQuery = () => "?" + Date.now()
export const getDateQuery = () => "?" + Date.now();

export const verifyLatLong = (refLat, refLong, lat, long, km) => {
let ky = 40000 / 360;
let kx = Math.cos((Math.PI * refLat) / 180.0) * ky;
let dx = Math.abs(refLong - long) * kx;
let dy = Math.abs(refLat - lat) * ky;
let result = Math.sqrt(dx * dx + dy * dy) <= km;

if (result) {
return true;
} else {
alert("Lütfen belirtilen şehir sınırları içerisinde bir lokasyon giriniz.");

return false;
}
};