Using Java, JS or Mysql to calculate the distance between two coordinates in Gaode map
preface
Because of my work, I recently used Gaode map in map related applications and studied the method of calculating the two coordinate distance of xiagaode map. There are relevant methods in the development package provided on the official website, but my products are special and can not directly use the provided methods, so I encapsulated the relevant calculation methods for your reference, I won't say much now. Let's take a look at the detailed introduction.
Java implementation
First, define a class for storing longitude and latitude, which is called lnglat
Calculation tools are as follows:
Finally, write a test code to test:
The running result is 1569.6213922679392. The example result of JavaScript API on the official website is as follows:
Although there is a little error in the result, it hi is within the acceptable range.
JavaScript implementation
The same algorithm is converted into the writing method of JS. The complete code is as follows:
MySQL implementation
summary
The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.