## How to calculate the distance between 2 points

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

### How to calculate the distance between 2 points

Hi,

I will try to explain my situation:
I am storing some coordinates of the map in a web database with a interface in PHP. I want to get just the latitude and longitude of the points which are in a specific radius. In the SQL instruction I put the condition:

"where SQRT(POW((point_latitude - ".\$_POST["latitude_center"]."),2) + POW((point_latitude - ".\$_POST["latitude_center"]."),2)) <= ".\$_POST["radius"]."

This calculates the distance between 2 points (analytic geometry). The point_latitude and point_longitude are stored in int

I'd like to know how I do this.

Last edited by cassianotartari on Thu Aug 28, 2008 6:47 pm, edited 1 time in total.
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}

cassianotartari
Developer

Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Just make it with a SQL statement.

I compare it with my two points like this

Code: Select all
`SELECT id , rout e id , count e r as count i , GPS lat i tude , GPS longitude ,us e r id , c a r id , vehi c l e spe ed , enginespeed , cur r entgear ,t a n k r e l a t i v e l e v e l , di s tanc e , ROUND( (ROUND( SQRT( POW( ( 6 9 . 1  (#s t a r t l a t i t u t e#  ( GPS lat i tude /1E6)) ) , 2) + POW( (53  ((#s t a r t l o n g i t u d e#)  ( GPS longi tude /1E6) ) ) ,2) ) , 8) 1.609344 ) , 4 ) AS d i s t a n c e s FROM da waypointWHEREu s e r i d <> #u s e r i d# AND count e r = 0GROUP BY r out e id ORDER BY d i s t a n c e s ASC`

with android you can take the Location... Object to calculate the distance
cbraun75
Junior Developer

Posts: 23
Joined: Mon Jan 28, 2008 9:12 pm
Location: Munich

cbraun75 wrote:Just make it with a SQL statement.

I compare it with my two points like this

Code: Select all
`SELECT id , rout e id , count e r as count i , GPS lat i tude , GPS longitude ,us e r id , c a r id , vehi c l e spe ed , enginespeed , cur r entgear ,t a n k r e l a t i v e l e v e l , di s tanc e , ROUND( (ROUND( SQRT( POW( ( 6 9 . 1  (#s t a r t l a t i t u t e#  ( GPS lat i tude /1E6)) ) , 2) + POW( (53  ((#s t a r t l o n g i t u d e#) ( GPS longi tude /1E6) ) ) ,2) ) , 8) 1.609344 ) , 4 ) AS d i s t a n c e s FROM da waypointWHEREu s e r i d <> #u s e r i d# AND count e r = 0GROUP BY r out e id ORDER BY d i s t a n c e s ASC`

with android you can take the Location... Object to calculate the distance

Sorry, I can't undestand the SQL because some characters not appeared, like the attach picture.
Attachments
bug enconding
screen.png (16.37 KiB) Viewed 752 times
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}

cassianotartari
Developer

Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

uups didn't see that.

OK Just try it again.

to get km from miles the * 1.609344 is required.
last round rounds on 4 digits after comma.

Code: Select all
`SELECT id, routeid, counter, GPS_latitude, GPS_longitude, user_id, car_id, vehiclespeed, enginespeed, currentgear, tankrelativelevel, distance,            ROUND((ROUND( SQRT( POW((69.1 * ([latitude] - ([GPS_latitude/1E6]))), 2) + POW((53 * (([longitude]) - ([GPS_longitude/1E6]))), 2)), 8)*1.609344 ),4) AS distances            FROM da_waypoint            WHERE user_id <> [user_id]             ORDER BY distances ASC`

cbraun75
Junior Developer

Posts: 23
Joined: Mon Jan 28, 2008 9:12 pm
Location: Munich

cbraun75 wrote:uups didn't see that.

OK Just try it again.

to get km from miles the * 1.609344 is required.
last round rounds on 4 digits after comma.

Code: Select all
`SELECT id, routeid, counter, GPS_latitude, GPS_longitude, user_id, car_id, vehiclespeed, enginespeed, currentgear, tankrelativelevel, distance,            ROUND((ROUND( SQRT( POW((69.1 * ([latitude] - ([GPS_latitude/1E6]))), 2) + POW((53 * (([longitude]) - ([GPS_longitude/1E6]))), 2)), 8)*1.609344 ),4) AS distances            FROM da_waypoint            WHERE user_id <> [user_id]             ORDER BY distances ASC`

Thanks

When I have time I will try it
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}

cassianotartari
Developer

Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

### Who is online

Users browsing this forum: No registered users and 6 guests