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

Postby cassianotartari » Thu Aug 28, 2008 4:01 pm

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.

Sorry with my bad english.
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"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Top

Postby cbraun75 » Thu Aug 28, 2008 5:19 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 waypoint
WHERE
u s e r i d <> #u s e r i d#
AND count e r = 0
GROUP 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
Junior Developer
 
Posts: 23
Joined: Mon Jan 28, 2008 9:12 pm
Location: Munich

Postby cassianotartari » Thu Aug 28, 2008 6:39 pm

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 waypoint
WHERE
u s e r i d <> #u s e r i d#
AND count e r = 0
GROUP 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
screen.png
bug enconding
screen.png (16.37 KiB) Viewed 510 times
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Postby cbraun75 » Mon Sep 01, 2008 7:55 am

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


Hope this could help you.
cbraun75
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Jan 28, 2008 9:12 pm
Location: Munich

Postby cassianotartari » Mon Sep 01, 2008 2:14 pm

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


Hope this could help you.


Thanks ;)

When I have time I will try it
public class pessoa {
private String nome = "Cassiano Tartari";
private String url = "www.cassianotartari.eng.br"
}
User avatar
cassianotartari
Developer
Developer
 
Posts: 28
Joined: Thu Aug 28, 2008 3:42 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests