Question

how to get city or place name through latitude and longitude

Asked by: Sachin_Ajmani

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..

 

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-24 at 06:19:46ID24676409
Topics

GIS & GPS Programming

,

MySQL Server

,

Databases Miscellaneous

Participating Experts
2
Points
500
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Latitude and Longitude
    Greetins, I have latitude and longitude values in minutes. Does nyone have a function to convert these numbers into a more readable format ? Thanks, Robert Lancaster
  2. compare longitude & latitude
    This isn't really a VB question but I am writing the app in VB and can't seem to find the formula. I would like to take 2 different longitude/latitude coordinates and compare them to see how far apart they are. If anyone has any examples I would appreciate it.
  3. Latitude and Longitude
    Hi, I am looking to find out what is the closest point based on Latitude and Longitude. For example, lets say i have a package at Location A, and I want to find out what carrier, pickup person, can pick it up based on the closest point. I have latitude and longitude coor...
  4. Latitude ,Longitude to Distance Conversion.
    Can any body tell me how to calculate distance between two points (latitude ,longitude given)on a map. Basically I want to know that with the difference of one degree how much will be the difference in Distance. That is One Degree = How much Distance(of course radius).
  5. latitude longitude database
    Where can I find an international latitude / longitude database similar to the us zip & canadian postal code databases that are fairly common. Thanks, DM
  6. Finding town/city from given latitude/longitude
    Is there a web service available which accepts latitude, longitude and returns the name of the town/city and the country. If the latitude/longitude is not of a town/city then the closest town/city name be made available along with distance to it and its bearing if possible.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: matthewstevenkellyPosted on 2009-08-24 at 07:36:46ID: 25168719

What you need to do is something like this: http://www.zcentric.com/blog/2007/03/calculate_distance_in_mysql_wi.html

Your device location would be the center point.

Use the lat and long from the device to find all the geonames that are within a minimum distance that you determine to allow them to be called a part of that city. You can then just use either the closest city or say no cities within 10km of your location, etc.

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

                                              
1:

Select allOpen in new window

 

by: Sachin_AjmaniPosted on 2009-08-24 at 22:09:21ID: 25174655

hi matthewstevenkelly
i try your query but i dont get success till now...

please tell me any other suggestion or example ..

 

by: pgnatyukPosted on 2009-08-25 at 11:27:08ID: 25180617

You, probably, have an access to a map data. If yes, you can find a nearest road. This road has a name. This is a street in a city. Maybe, you can do the same with the post code.
Another way is to use, for example, Google Map API:
http://code.google.com/apis/maps/

http://code.google.com/apis/maps/documentation/

or something like that.

 

by: matthewstevenkellyPosted on 2009-08-25 at 15:46:04ID: 25183026

What version of MySQL are you running?

The $lat and $long were meant to be replaced with the latitude and longitude. Sorry, so used to PHP & MySQL together... did not realize it was not in this category.

Try the following query:

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

                                              
1:

Select allOpen in new window

 

by: Sachin_AjmaniPosted on 2009-08-25 at 23:42:28ID: 25184903

hi matthewstevenkelly

thanks for your reply.. your query working fine but its very slow to execute..

i m using 5.1.36 MySql version please tell me how can i  fast execute my query this time it is taking 14.246 seconds.

so you can see its too slow to execute..

thanks in advance..

 

by: matthewstevenkellyPosted on 2009-08-26 at 13:37:09ID: 25191988

Could you post the table structure of geonames?

Increase speed by:
 - Making Latitude and Longitude keys in the table
 - Instead of '*' only put the fields you need (ie City name)

Worse case you could try to find close cities by decimal truncation

ie instead of

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

do

select * from geonames where LONGI='76.9915' AND LAT='29.3356';

And use the top city returned.

But the results would not be as accurate.

 

by: Sachin_AjmaniPosted on 2009-08-26 at 21:23:41ID: 25194576

hi matthewstevenkelly

i am getting result from this query but its execution is too slow ie 14.2 sec.

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

and i try

select * from geonames where LONGI='76.9915' AND LAT='29.3356';

but it returns null;

 

by: Sachin_AjmaniPosted on 2009-08-26 at 21:27:16ID: 25194596

my table structure is



CREATE TABLE geonames (`RC` VARCHAR(255), `UFI` VARCHAR(255), `UNI` VARCHAR(255), `LAT` VARCHAR(255), `LONGI` VARCHAR(255), `DMS_LAT` VARCHAR(255), `DMS_LONG` VARCHAR(255), `MGRS` VARCHAR(255), `JOG` VARCHAR(255), `FC` VARCHAR(255), `DSG` VARCHAR(255), `PC` VARCHAR(255), `CC1` VARCHAR(255), `ADM1` VARCHAR(255), `ADM2` VARCHAR(255), `POP` VARCHAR(255), `ELEV` VARCHAR(255), `CC2` VARCHAR(255), `NT` VARCHAR(255), `LC` VARCHAR(255), `SHORT_FORM` VARCHAR(255), `GENERIC` VARCHAR(255), `SORT_NAME` VARCHAR(255), `FULL_NAME` VARCHAR(255), `FULL_NAME_ND` VARCHAR(255), `MODIFY_DATE` VARCHAR(255));
                                              
1:

Select allOpen in new window

 

by: Sachin_AjmaniPosted on 2009-08-26 at 21:28:09ID: 25194605


RC	UFI	UNI	LAT	LONGI	DMS_LAT	DMS_LONG	MGRS	JOG	FC	DSG	PC	CC1	ADM1	ADM2	POP	ELEV	CC2	NT	LC	SHORT_FORM	GENERIC	SORT_NAME	FULL_NAME	FULL_NAME_ND	MODIFY_DATE	distance
5	6231763	6255272	29.336111	76.979167	292010	765845	43RFN9216446851	NH43-12	P	PPL		IN	10					N				SIWAH	SiwÄýh	Siwah	2003-02-06	0.745162782586395
                                              
1:
2:

Select allOpen in new window

 

by: Sachin_AjmaniPosted on 2009-08-26 at 21:28:42ID: 25194607

above are row values with header name

 

by: matthewstevenkellyPosted on 2009-08-27 at 14:39:42ID: 25202992

I meant this sorry,

select * from geonames where LONGI LIKE '76.9915%' AND LAT LIKE '29.3356%';

Adding an index will significantly increase performance. Add an index to the LONGI and LAT:

CREATE INDEX long_idx ON geonames (LONGI(10));
CREATE INDEX lat_idx ON geonames (LAT(10));

The only caveat to indexes is they consume memory, but fields that are used heavily in WHERE statements should be indexed to improve performance.

 

by: Sachin_AjmaniPosted on 2009-08-27 at 22:40:10ID: 25205157

hi matthewstevenkelly

i got how to increase performance but my problem is still alive..

i used your query

select * from geonames where LONGI LIKE '76.9915%' AND LAT LIKE '29.3356%';

after created index it fast executes but returns null;

bcoz the original lat and long for this place are 29.336111 and 76.979167.

but i got from my device  LONGI='76.9915264' AND LAT='29.3356256';

so when i used  select * from geonames where LONGI LIKE '76.9915%' AND LAT LIKE '29.3356%';

it returns null bcoz of different lat and long and when i changed manually   select * from geonames where LONGI LIKE '76.97%' AND LAT LIKE '29.33%';

than it returns my place which i want.

tell me now where i wrong ?

thanks ..

 

by: Sachin_AjmaniPosted on 2009-08-27 at 22:42:27ID: 25205170

and apart questioning i visit your personal website .. it is very good to see.

 

by: matthewstevenkellyPosted on 2009-08-28 at 15:34:00ID: 25212074

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.

 

by: Sachin_AjmaniPosted on 2009-08-30 at 22:45:01ID: 25220699

hi matthewstevenkelly
 
Sorry pal i was on holidays therefore i was not able to reply. Today i m trying your query as soon as i got successes than i will inform you.

thanks



 

by: Sachin_AjmaniPosted on 2009-09-01 at 04:23:15ID: 31619628

thanks

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...