Question : how to get city or place name through latitude and longitude

hi experts,

i m working on gps project and i m stuck somewhere ... i have geonames in my database and i also have latitude and longitude but i dont know how to i get city or place name of that lat and long..

i m trying with this query

These are panipat (INDIA) co-ordinates..
Longitude ::: 76.968056
Latitude   :::: 29.388889

I get longitude 76.9915264 and latitude 29.3356256 from my device and these co-ordinates just 5 km far from panipat but comes in panipat and not present in my database because every place has different lat and long as all knows..

so if i try this

select * from geonames where LONGI='76.9915264' AND LAT='29.3356256';

than it returns null because these co-ordinates are not original panipat co-ordinates.

please help me to out this .

thanks in advance..

 

Answer : how to get city or place name through latitude and longitude

Thanks for the compliment.

After creating the indexes, is this query faster? This will give you the most accurate results:

SELECT *, ((ACOS(SIN('29.3356256' * PI() / 180) * SIN(Latitude * PI() / 180) + COS('29.3356256' * PI() / 180) * COS(Latitude * PI() / 180) * COS(('76.9915264' - Longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM geonames HAVING distance<='10' ORDER BY distance ASC


In order for this query you would have to trim it down to one decimal place:

select * from geonames where LONGI LIKE '76.9%' AND LAT LIKE '29.3%';

1 degree is 69.2 miles so trimming it down to .1 degree would be 7 miles. Not sure your required accuracy.

Even better (if the first query in this post does not work) would be:

Select * from geonames where LONGI > '76.9415264' AND LONGI < '77.0415264'  AND LAT > '29.2856256' AND LAT < '29.3856256';

Where you add and subtract 0.05 from the results from the device to get a 0.1 (7 mile) range...

Let me know how the first query executes.... it should be fast with the index's.
Random Solutions  
 
programming4us programming4us