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.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>