How to find latitude and longitude lies within radius? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have latitude and longitude of place. How to find these latitude and longitude lies within some other locations radius?
for example having (6.8914,79.8522) (lat,long) of location,and find within location (6.9584218,80.1783008) of radius 10.
please help me.

lat1 = 6.8914 # latitude of point 1
long1 = 79.8522 # longitude of point 1
lat2 = 6.9584218 # latitude of point 2
long2 = 80.1783008 # longitude of point 2
if distance between two geographical points < 10:
point2 lies inside radius
else:
it doesn't
You may seek idea how to calculate distance between two geographical points and the programmatical implementation by using Haversine Formula here.

Related

Calculate distance from current Latitude and Longitude with different Latitude and Longitude in one kilometer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have problem I think but I can not find the ideal solution. I am storing different restaurant locations latitude and longitude in Mysql table. I want to find a restaurant around 1 km radial distance from current location of user using latitude and longitude so how to do this. I have to show all restaurants which are in 1 km radius from user current location latitude and longitude.
This is the formula of distances using longitude and latitude
a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 * atan2( √a, √(1−a) )
d = R * c
//Where φ represent the latitudes, and λ represent the longitudes.
Reference: https://www.sisense.com/blog/latitude-longitude-distance-calculation-explained/
Also you can check this page for using javascript.
https://www.movable-type.co.uk/scripts/latlong.html
Remember that latitude and longitude originally are writed on degrees, I think you first need to know how much distance represents 1º, on some books and websites it says that 1º is about 111km depending how near is the spot from the equator line, so (more or less):
1º - 111km, also 1º equals 60'
then 1' should be 1.85km, and 1' equals 60"
then 1" is more or less 0.03km
so 32.4324" is about 1km
Now... basically you need to now the limits of a square based on the initial location, for this just add/substract 32.4324" to latitude and longitude, so give it a try.. lets go to las vegas (use google maps)
36.1699412,-115.1398296
This locations is on a sexagesimal notation son lets convert 32.4324".. its simply... just divide it on 3600 and that is 0.009009009, this is the value you must add/subtract to/from latitude/longitude
north bound, after add: 36.1789502
south bound, after substract: 36.1609322
east bound, after add: -115.1308206
west bound, after substract: -115.1488386
now on gmaps try to locate these bounds for ex (north bound: 36.1789502,-115.1398296) you will see is just above original location, you can also measure distance from original location up to 1km and that is more or less near to the north bound you just calculated.
so now, just query your database and filter it where latitude is between north bound(36.1609322) and south bound(36.1789502), and also longitude is between west bound(-115.1488386) and east bound(-115.1308206) and that should do the work. So the magic is just to add/substract 0.009009009 to any location point.

Selecting points within a bounding square [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Help to make a selection from the database (mysql) of the coordinates.There is a table with fields latitude/longitude.The sample should be in the form of a rectangle. Thank you! example
I tried it http://www.movable-type.co.uk/scripts/latlong-db.html, but it is necessary in the form of a predetermined size of the rectangle
If you need select the point inside a rectangle is
Assuming that your rect have thr coord ($minLat , $minLng , $maxLat, $maxLng)
You can simply select the points this way
select * from my_table
where
point_lat >= $minLat
AND point_lat <= $maxLat
AND point_lng <= $maxLng
AND point_lng >= $minLng;

How to filter database results by nearness of gps location? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm getting a GPS location via an android app and then asking the server which of the records in the database are near it.
How can I accomplish this?
Let's say that these are the coordinates:
39.017411, -97.251117
How can I ask the database in PHP to only give me the results that contain coordinates near those?
You can do something like as mentioned below, considering field name of your table is lat for latitude and lng for longitude
$lat = 39.017411;
$lng = -97.251117;
$result=mysql_query("SELECT tbl.id, tbl.lat, tbl.lng, 111.045 * DEGREES(ACOS(COS(RADIANS($lat))
* COS(RADIANS(lat))
* COS(RADIANS(lng) - RADIANS($lng))
+ SIN(RADIANS($lat))
* SIN(RADIANS(lat))))
AS distance_in_km
FROM table_name as tbl
ORDER BY distance_in_km ASC
LIMIT 0,1");
if(mysql_num_rows($result)>0)
{
$row=mysql_fetch_assoc($result));
echo $row[lat].";".$row[lng];
}

Clark's formula - population density [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a problem:
C. Clark's model of urban population densities indicating that population density varies with distance from the center of the city according to the equation Dx=D0e-bx where Dx is the population density at distance x from the center. D0 is the density at the center, e is the base of the natural logarithms, and b is a natural logarithm measuring the rate of change of density with distance.
How can I write this formula in php language?
Thanks!
What I have tried:
Dx = D/(x/b*b);
But I thinks this is wrong.
Not sure what's the problem here, so here's how I got it and you can say what did I get wrong. Afterwards, you can edit your question :)
Hence:
// this should be given
$d0 = 1.22;
$b = 0.37;
function dx($x = 0) {
global $d0, $b;
return $d0 /exp($b*$x);
}
echo dx(6.74); // d_{6.74}

Calculating distance between two points on a flat plane? (php) [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
3rd grade question:
How do you calculate the distance between two points on a flat surface?
I have been going through the Google_Results and it seems everything i find applies to Long/Lat and not a flat surface.
I'm working on making ObjectA choose between ObjetsC,D,E... , select the closest one and move toward it. So I have to loop through my SQL table, pull out what's in range, and loop through the results to calculate distances.
Any help with this math I haven't had to remember in years would be appreciated.
You will need to use a Euclidean distance formula (specifically for 2 dimensions). Basically the formula is:
d = sqrt((x1 - x2)^2 + (y1 - y2)^2)
d is your final distance
sqrt is the square root (the sqrt() function in PHP)
x1 and y1 are your x-y coordinates for your first point
x2 and y2 are your x-y coordinates for your second point
^2 means raise to the second power (use the pow() function for PHP)
Pythagoras was the Greek philosopher who developed the Pythagorean Theorem, which can be used to derive the 2-dimensional distance formula (which is different from Euclid's derivation).

Categories