Home Answers Viewqa Java-Beginners Road distance using Java

 
 


sameer
Road distance using Java
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners

View Answers

August 19, 2009 at 12:32 PM


Hi Friend,

We are providing you a code that will prompt the user to enter the latitude and longitude coordinates of the source and destination and accordingly return the distance between them.

import java.util.*;

public class CalculateDistance{
public static void main(String args[]){
System.out.println("Enter the Longitude and Latitude of Source location:");
Scanner input=new Scanner(System.in);
double lat1=input.nextDouble();
double long1=input.nextDouble();
System.out.println("Enter the Longitude and Latitude of destination location:");
double lat2=input.nextDouble();
double long2=input.nextDouble();
CalculateDistance cal=new CalculateDistance();
double dist=cal.distance( lat1, -long1 ,lat2 , -long2, 'K');
System.out.println(dist + " Kilometers\n");
}

public static double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta = lon1 - lon2;
double dist = Math.sin(degreeToRadian(lat1)) * Math.sin(degreeToRadian(lat2)) + Math.cos(degreeToRadian(lat1)) * Math.cos(degreeToRadian(lat2)) * Math.cos(degreeToRadian(theta));
dist = Math.acos(dist);
dist = radianToDegree(dist);
dist = dist * 60 * 1.1515;
if (unit == 'K') {
dist = dist * 1.609344;
}
return (dist);
}
private static double degreeToRadian(double deg) {

return (deg * Math.PI / 180.0);
}
private static double radianToDegree(double rad) {
return (rad * 180.0 / Math.PI);
}

}

Thanks









Related Pages:
Road distance using Java - Java Beginners
Road distance using Java  Dear All i am calculating the straight line distance between two latlong points using the simple mathematical formula but i need the Real Road Driving Distance // protected double distance(double pX
Delhi to Udaipur by road distance
Delhi to Udaipur by road distance  delhi to udaipur by road distance
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
Distance in meters - Java Beginners
Distance in meters  Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections... the program The program will convert the distance to kilometers, inches
SMART VEHICLE ROAD SIGN IDENTIFICATION
SMART VEHICLE ROAD SIGN IDENTIFICATION  JAVA code for "SMART VEHICLE ROAD SIGN IDENTIFICATION
Distance conversion - Java Beginners
Distance conversion  Write an application that reads a distance... the distance to kilometres, feet and inches, according to the user?s selection...() for the user selection. ? Write a method to read a distance in metres from
Another distance conversion - Java Beginners
Another distance conversion  Write an application that reads a distance in metres. The program will then convert the distance to kilometres, feet...[]){ System.out.print("Enter distance in meters : "); BufferedReader br = new BufferedReader(new
GUI and how to convert a distance - Java Beginners
application that can be is used to convert a distance unit in miles into its...=new JTextField(20); t5=new JTextField(20); l1=new JLabel("Enter distance...){ String value=t1.getText(); double distance=Double.parseDouble(value
class distance
class distance  class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required
Delhi to Udaipur by road
Delhi to Udaipur by road  Please guide me an easy and the shortest road route from Delhi to Udaipur. Thanks
How to make a damaged road, make a damaged road, damaged road
How to make a damaged road       If you want to convert a fresh road to damaged mode come... a picture: First we have take a fresh road picture as I have taken here
Hill stations near Delhi distance
Hill stations near Delhi distance   Hi, Can any one tell the distances of the Hill stations near Delhi? Thanks
Vehicle Tracking
; IF YOUR VEHICLE GOES TO the road, anything can happen to the vehicle; may meet... be seen on a computer screen and using mapping software you can see the exact... based on vehicle’s position, speed and distance traveled and duration
read xml using java
read xml using java  <p>to read multiple attributes... also generates the road slope state (RSL_STATE). Input for this Module... to other interacting modules, as communication is only allowed to take place using
Distance learning business management
Distance learning business management courses are on high demand today.... But those students should not worry as many institutions have started distance... for the future and skilled workforce. Distance learning business management courses
Hill Stations near Delhi distance
Distance of Major Hill Stations From Delhi  In this page we have listed all the Hill Stations near Delhi with their distance from central Delhi... and northeastern India. List of Hill Stations near Delhi with distance Sr
VoIP Long Distance
VoIP Long Distance          VoIP Designing a Long-Distance Network The long-distance Voice over IP (VoIP) network solution is a set of network design
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  ...; private double distance; public Travel() { time=0; distance=0... getDistance() { return distance; } public static void main (String[] args
How GPS Measures Distances
of an object using distance measurements from at least three satellites. Let us now examine how distance from the satellites is calculated. The Principle... are calculating the distance using the time radio signals take to travel from the satellites
JAVA
JAVA  plz send me code, How to find fare form one place to another place using Java,Jsp,Servlets? for example:i need to calculate from bangalore to gulbarga..i need to claculate the bus fare,distance in kms
Using throw in java method
Using throw in java method  using throw with method implies what
write a programm using java
write a programm using java  print the following using java programming
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
survey poll using java
survey poll using java  how to make a survey poll using java? i am using netbeans and glassfish
RARP program using java
RARP program using java   hai, how to implement the RARP concept using java
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java
Image using Java coding
Image using Java coding  Hai, Display image in pdf file using Java coding through Xsl file.. Please help me.. xsl file generate the pdf file
covert the following using java
covert the following using java  how to convert (for eg : 2.89) . this decimal to binary in java
accessing xml using java
accessing xml using java  I need to retrieve some elements in xml file using java   Hi Friend, Please visit the following links: http://www.roseindia.net/xml/Listingnode.shtml http://www.roseindia.net/xml/getting
uSING JAVA API
uSING JAVA API  How to extract Quickbooks online data using Quickbooks api( Rest ApI) write in java code ? 1.register company account 2..register application 3.get apptoken,consumer key,consumer screte 4.how can i
using java files - Java Beginners
using java files  how i use files in java to store as eg. (information about movies as its name) & when user ask about some movie the movie will come with a picture associated with it plz write me a couple of line codes
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know.../xmlParsing/java-xml-parsing-using-sax.shtml http://www.roseindia.net/xml/sax...Read XML using Java  Hi All, Good Morning, I have been working
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java? whats the java program or code to that. Thank you rose india and java experts  Hi Friend, Try the following code: import java.util.
JSP using java - Java Beginners
JSP using java  sir, In my jsp page contains 3 hyperlinks say (link1 link2 link3).I want to write some java code using servlet for each hyperlinks.how to forward JSP page to servlet.I m using 3 hyperlinks in my page.My
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert... and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert... and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert... and postgresql as data base syntax which i m using is like:- java class
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can you help me out !!.......i wanna to know the appropriate java syntax to insert... and postgresql as data base syntax which i m using is like:- java class
java using JSP - Java Beginners
java using JSP  hi...i has been created one JSp page.in this page have one links name as "Show datas in Excel format".I want to create Excel file... using postgres DB.This DB have more than 4 Rows and Columns.  Hi Friend
Java Programming using array
Java Programming using array  I'm creating a programming using array that will accept 10 letters and test if those letters are consonant, then it will display on the screen. Please guide me. Sample Output: Enter 10 letters
java in using brausing
java in using brausing  sir, i am beginner java developer ,sir i am creat's the image viewer Jframe but not a created frame plz. halpe me give the image viewer Jframe code   import java.io.*; import java.awt.
OOP using Java - Java Beginners
OOP using Java  Can you write a Java statement that creates the object mysteryClock of the Clock type, and initialize the instance variables hr,min...); } } For more information on Java visit to : http://www.roseindia.net/java
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
How to design a form using java?
How to design a form using java?  Please help in designing of form using java for my project
Using swing - Java Beginners
Using swing  How can one use inheritance and polymophism while developing GUI of this question. Develop an application that allows a student to open an account. The account may be a savings account or a current account
JSP using java - Hibernate
JSP using java  This is my part of Excal sheet code using jdbc connection. int index=1; while(rs.next... using hibernate.I am having function called displayIps() and displayvalues
OOP Using JAVA - Java Beginners
OOP Using JAVA  OBJECT ORIENTED PROGRAMMING USING JAVA (hope guys u will help me please i need your help,thank you so much) Create a Java program...(); oops.OopType(); } } For more information on Java visit to : http
Java using Jsp - Java Beginners
Java using Jsp  hi sir, again i m getting error like. HSSFWorkbook cannot be resolved to a type. HSSFSheet cannot be resolved to a type. HSSFRow cannot be resolved to a type I included Maximum all jar file in eclipse
Using a JFileChooser - Java Beginners
Using a JFileChooser  Dear Editor, How to select an image from JFileChooser & add the image in mySQL5 database? Thanks in advanced. Regards, Melvin.  Hi Friend, Try the following code: import java.sql.