This is the mutual conversion method of Mochato coordinates and Mars coordinates of Baidu map. Please refer to it.
The code copy is as follows:
/**
* Encryption and decryption algorithm of Baidu Mocha drag coordinates and Mars coordinates
* @author XFan
*
*/
public class Outer {
private static double lat = 31.22997;
private static double lon = 121.640756;
public static double x_pi = lat * lon / 180.0;
public static void main(String[] args) {
System.out.println("Mocha coordinate latitude and longitude:"+lat+","+lon);
System.out.println("Mars coordinates latitude and longitude:"+bd_decrypt(lat,lon));
}
//Decryption becomes Mars coordinate
public static String bd_decrypt(double bd_lat, double bd_lon)
{
double x = bd_lon - 0.0065, y = bd_lat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
double gg_lon = z * Math.cos(theta);
double gg_lat = z * Math.sin(theta);
return gg_lat+","+gg_lon;
}
//Encryption becomes Mochato coordinate
public static String bd_encrypt(double gg_lat, double gg_lon)
{
double x = gg_lon, y = gg_lat;
double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
double bd_lon = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
return gg_lat+","+gg_lon;
}
}