Hello,

I need to view all the notable places may be around some 10 kilometers using my current place latitude and longitude.

I had searched but got ans as getting places from DB, but am not looking for it.

If any one can help me , it will be great for me.

waiting…

Thnx.

Create a "DISTANCE_GPS" function in mysql:

```
CREATE FUNCTION `DISTANCE_GPS`(`lat1` DOUBLE, `lon1` DOUBLE, `lat2` DOUBLE, `lon2` DOUBLE) RETURNS double
NO SQL
BEGIN
DECLARE dist DOUBLE;
DECLARE latDist DOUBLE;
DECLARE lonDist DOUBLE;
DECLARE a,c,r DOUBLE;
SET r = 6371000;
SET latDist = RADIANS( lat2 - lat1 );
SET lonDist = RADIANS( lon2 - lon1 );
SET a = POW( SIN( latDist/2 ), 2 ) + COS( RADIANS( lat1 ) ) * COS( RADIANS( lat2 ) ) * POW( SIN( lonDist / 2 ), 2 );
SET c = 2 * ATAN2( SQRT( a ), SQRT( 1 - a ) );
SET dist = r * c;
RETURN dist;
END
```

and the use it:

```
SELECT DISTANCE_GPS(43.1, 12.3, gps_lat, gps_long) FROM mytable
```

where gps_lat and gps_long are two fields from mytable and 43.1,12.3 is a gps position.

Hello fab,

First of all thanks for the response.

I want to view nearby places which around one latitude and longitude, like how the google map views. I have only one place lat & lang in my table "Geo". using that I want to view places which is near to that lat & lang.

(Am using php+mysql phpmyadmin)(Yii2)

Thnx.

Using DISTANCE_GPS function, you can apply a condition such as:

```
SELECT * FROM mytable WHERE DISTANCE_GPS( 43.1, 12.3, gps_lat, gps_long) < 50
```

where 50 (in kilometers) is comparing distance.

Using DISTANCE_GPS function, you can apply a condition such as:

```
SELECT * FROM mytable WHERE DISTANCE_GPS( 43.1, 12.3, gps_lat, gps_long) < 50
```

where 50 (in kilometers) is comparing distance.

If you don’t mind can you tell me where do I put that gps function?? am new to this.

Am using php yii2 framework.

You have to write that code sql code inside mysql db, so you will have DISTANCE_GPS available for next SELECT calls.

salmaHabib
(Salma0692)
October 26, 2017, 12:21pm
7
Hi,

I could not create function so I had created procedure am getting some numbers dont no what to do with it and how it helps me to find nearby places. please explain.

I called procedure

```
call distance_gps( 43.1, 12.3, 8.803980200000002, 78.1436599 )
Ans : 7386740.627661293
```

If you get an answer, you have created a function.

DISTANCE_GPS function accepts 4 parameters : lat1, lon1, lat2, lon2,

where lat1 and lon1 are latitude and longitude of first point and lat2 and lon2 are latitude and longitude of second point.

salmaHabib
(Salma0692)
October 26, 2017, 12:43pm
9
If you get an answer, you have created a function.

DISTANCE_GPS function accepts 4 parameters : lat1, lon1, lat2, lon2,

where lat1 and lon1 are latitude and longitude of first point and lat2 and lon2 are latitude and longitude of second point.

Fab,

Rather function I had created procedure, when I called I get some number which I have mention in previous reply, Using that how do I print or echo Near by places names and one more thing while calling procedure how do I use condition (>50).

Thanku for your responses fab.

Thnx,

You have to build a sql based on that function (DISTANCE_GPS) applying a filter based on max distance.

Post some code if it is not clear.