Yichun Zhao JAVA Notes

My Java Online Notes

Saturday, 20 May 2017

Calculate distance when knowing longitude and latitude in java

Maven Dependency 

<dependency>
  <groupId>com.javadocmd</groupId>
  <artifactId>simplelatlng</artifactId>
  <version>RELEASE</version>
</dependency>

Getting Started
SimpleLatLng is written and compiled to Java 6. After you have included the library jar in your project or added it as a dependency in your build tool of choice, you can create a point in latitude and longitude as follows:

LatLng point = new LatLng(33.123123, -127.123123);
The important thing to note is that all latitudes and longitudes are handled in degrees using the convention that positive latitudes are in the northern hemisphere and positive longitudes are east of the Prime Meridian.

This library generally considers degree measurements to the millionth (0.000001) degree. So 33.0000010 is equal to 33.0000015, but not equal to 33.0000020. This yields a resolution of around 1 centimeter which is far more accurate than the distance calculations require.

When a LatLng point is constructed, its latitude and longitude will be normalized to fall within the ±90 degrees latitude, ±180 degree longitude range. Special case: if your LatLng is constructed at a pole (±90 degrees latitude), its longitude will be set to 0 because all longitudes intersect at the poles.
Distance between two points

To calculate the distance between two points, use the static methods in LatLngTool.
LatLng point1 = new LatLng(33.123123, -127.123123);
LatLng point2 = new LatLng(33.321321, -127.321321);
double distanceInMiles = LatLngTool.distance(point1, point2, LengthUnit.MILE);
All supported units of length are contained by the enum LengthUnit. We will add supported units if there is call for them.

Reference 

SimpleLatLng is a Java implementation of common latitude and longitude calculations.

Algorithm to find all Latitude Longitude locations within a certain distance from a given Lat Lng location

Spring Data Elasticsearch

index Latitude and Longitude and fast SQL query

at May 20, 2017
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...

  • Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content type [application/octet-stream]
    Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content ...
  • More than one row with the given identifier was found: 8
    First time met this hibernate exception. I think this issue should due to one to one relationship. One driver has one car; one car has on...
  • Caused by: org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.
    A large object refers to the entity property that is modified by @Lob. It may be persisted in several records. However, in database manage...

About Me

Yichun Zhao
View my complete profile

Blog Archive

  • September (2)
  • July (1)
  • June (1)
  • April (4)
  • March (2)
  • February (1)
  • January (1)
  • November (1)
  • September (5)
  • August (3)
  • July (1)
  • June (1)
  • July (3)
  • June (8)
  • May (3)
  • April (2)
  • March (1)
  • February (3)
  • January (9)
  • December (1)
  • October (1)
  • August (2)
  • July (4)
  • May (1)
  • April (2)
  • December (1)
  • October (8)
  • September (7)
  • August (4)
  • June (1)
  • May (2)
  • April (2)
  • February (1)
  • December (5)
  • September (2)
  • August (1)
  • July (2)
  • June (1)
  • May (5)
  • April (1)
  • March (5)
  • February (2)
  • January (2)
  • November (1)
  • October (1)
  • September (1)
  • August (4)
  • July (1)
  • June (2)
  • May (7)
  • April (6)
  • March (1)
  • November (1)
  • September (4)
  • August (9)
  • June (13)
  • May (20)
  • April (2)
  • March (2)
  • June (1)
  • September (3)
  • July (1)
  • March (1)
  • October (1)
  • September (1)
  • August (3)
  • April (1)
  • November (1)
  • September (5)
  • August (3)
  • July (4)
  • June (4)
  • May (1)

Labels

  • Algorithm
  • BigNumber
  • Database
  • Docker
  • Email
  • Exception
  • File IO
  • Generics and Collections
  • Git
  • GMap API
  • Heroku
  • IDE
  • Java 8
  • JavaCharts
  • JDBC
  • JPA-Hibernate
  • K8s
  • Keyword
  • Linux
  • Log
  • LomBok
  • MacOS
  • Maven
  • microservice
  • OCPJP
  • OOAD
  • Overriding
  • PaaS
  • Patterns
  • Performance
  • Persist LOB using JPA in J2EE/J2SE
  • PostgreSQL
  • Regx
  • Spring
  • SpringBoot
  • SpringBoot Test
  • SQL
  • Test
  • Threads and Concurrency
  • Time Complexity
  • URI

Report Abuse

  • Home

Search This Blog

Simple theme. Theme images by luoman. Powered by Blogger.