I get stuck in the middle of my project which is a java application , where i need to calculate a approximate distance between two cities . But i am not getting anything by googling . I explore the Google Map API, but they provide it with JavaScript , There are some classes like GRoute which gives me distance , but not able to proceed further with it !!
Is any other Java API i can use or any programming logic or data structure i can use to solve tis problem ?
Googling for "distance between cities" finds a number of online applications. If nothing better comes along, you should be able to drive one of those using the HttpUrlConnection class, and then parsing the resulting HTML.
Hi So you means i need to hit a site which offer to calculate distence between two cities and parse the repsonse html file for desired oupput distance !! But how can i set that parameter of 'From City' to 'To city' on that site ?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35222
7
posted
0
Here's an example of how to post a form with parameters and read the response that is being sent.
This site gives distance between cities only whic comes under US and Canada territories . Plus it is not a free service .
Still thanks for the help , I am already found a site which gives not Distance , but Longitude and latitude , which help to calculate the approximate distance
Vikas Kapoor
Ranch Hand
Joined: Aug 16, 2007
Posts: 1374
posted
0
Hi Sagar,
This may help you.It gives many information like distance in kilometer,miles. It provides longitude,latitude and much more. And it's free. [ May 15, 2008: Message edited by: Vishal Pandya ]
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
0
There will be classes and methods in java.awt that convert rectangular screen co-ordiantes to polar co-ordinates. You can provide the appropriate class with (int x, int y, int delta-x, int delta-y) using city first(x,y) for the first two then city second(x,y) to the second pair of ints then call rectangular to polar and get magnitude on the result.
To do surface of Earth ( Great Circle Distance ) is complex, but one does not get asked to do Great Circle Distance unless your instructor is a Pilot or Astronomer.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
Two methods which do what Nicholas Jordan suggests are Math#atan2() and Math#hypot. But they do assume you are working on a flat surface.
But i already started working on what 'Ulf Dittmer' was suggest . I hit the URL to get XML file as a response and extract longitude and latitude , which gives me a approximate distance (i.e a straight nautical distance )
Hey thanks ahmd and welocme to JavaRanch I already implemented my requirement, (which is a year old) and its working fine.
I hadn't explore the library yet, but one question for you ?
Can I calculate the distance of any city of the word to any city ? And a short description about how it calculate the longitude and latitude of a city, I mean is it request this data from internet or do you have you own logic/data structure inside.
Ahmed Taha
Greenhorn
Joined: Jul 10, 2009
Posts: 2
posted
0
it is just calculate the Distance between Latitude and longitude coordinates
i assume you know the Latitude and longitude coordinates of the city
Ahmed Taha wrote:it is just calculate the Distance between Latitude and longitude coordinates
i assume you know the Latitude and longitude coordinates of the city
Ohh, Ok. Got it.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
4
posted
0
Ahmed Taha wrote:You can use the LatLongLib , from this post
Please don't post that sort of answer to a year-old thread. Read this.