凯立德地图 将地理坐标转换为经纬度
2017-12-31 14:49
716 查看
前言:因项目需求以及客户提出的要求要将百度地图更换为凯立德地图,因此就牵扯到经纬度转换的问题,凯立德官方文档对这方面提供的信息少,没有找到合适的解决方案,所以在几经周折总算是找到一个比较委托的解决办法。
地理坐标:437438300,134912100
(第一个参数代表经度,第二个代表维度)
K码:8q91f4apv
经纬度:121.42437,37.415793
(参数仅供参考)
说明:
凯立德地图 api 获取地理坐标以及K码都有相应的api,大家可以尽情调取,这里只根据K码转换为经纬度
因此请看转换的demo(java代码)
============================================================
由凯立德 k码 转换为经纬度
public class KCode {
private double longitude;
private double latitude;
private byte[] map34 = new byte[123];
public KCode() {
map34['0'] = 0;
map34['1'] = 1;
map34['2'] = 2;
map34['3'] = 3;
map34['4'] = 4;
map34['5'] = 5;
map34['6'] = 6;
map34['7'] = 7;
map34['8'] = 8;
map34['9'] = 9;
map34['a'] = 10;
map34['b'] = 11;
map34['c'] = 12;
map34['d'] = 13;
map34['e'] = 14;
map34['f'] = 15;
map34['g'] = 16;
map34['h'] = 17;
map34['i'] = 18;
map34['j'] = 19;
map34['k'] = 20;
map34['m'] = 21;
map34['n'] = 22;
map34['p'] = 23;
map34['q'] = 24;
map34['r'] = 25;
map34['s'] = 26;
map34['t'] = 27;
map34['u'] = 28;
map34['v'] = 29;
map34['w'] = 30;
map34['x'] = 31;
map34['y'] = 32;
map34['z'] = 33;
}
public double getLongitude() {
return longitude;
}
public double getLatitude() {
return latitude;
}
//
private int pow34(int i)
{
int sum = 1;
while(i > 0)
{
sum *= 34;
--i;
}
return sum;
}
//
private int Convert34to10(String str34)
{
int sum = 0;
for(int i = 0; i < str34.length(); ++i)
{
if( (str34.charAt(i) != 'l' && str34.charAt(i) != 'o') &&
((str34.charAt(i) >= '0' && str34.charAt(i) <= '9') ||
(str34.charAt(i) >= 'a' && str34.charAt(i) <= 'z'))
)
{
sum += map34[ str34.charAt(i)] * pow34(i);
}
else
{
System.out.println("invalid chaa");
return -1;
}
}
return sum;
}
//
public int Convert(String kcode)
{
if(kcode.length() != 9)
{
return -1;
}
int lut,lat;
char quad = kcode.charAt(0);
switch(quad)
{
case '5':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 105;
latitude = (double)lat / (3600 * 10) + 40;
break;
case '6':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 70;
latitude = (double)lat / (3600 * 10) + 40;
break;
case '7':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 70;
latitude = (double)lat / (3600 * 10) + 5;
break;
case '8':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 105;
latitude = (double)lat / (3600 * 10) + 5;
break;
default:
}
return 0;
}
public static void main(String[] args) {
KCode code = new KCode();
code.Convert("8q91f4apv");
System.out.println(code.getLongitude());
System.out.println(code.getLatitude());
}
} 上述代码仅供参考。
地理坐标:437438300,134912100
(第一个参数代表经度,第二个代表维度)
K码:8q91f4apv
经纬度:121.42437,37.415793
(参数仅供参考)
说明:
凯立德地图 api 获取地理坐标以及K码都有相应的api,大家可以尽情调取,这里只根据K码转换为经纬度
因此请看转换的demo(java代码)
============================================================
由凯立德 k码 转换为经纬度
public class KCode {
private double longitude;
private double latitude;
private byte[] map34 = new byte[123];
public KCode() {
map34['0'] = 0;
map34['1'] = 1;
map34['2'] = 2;
map34['3'] = 3;
map34['4'] = 4;
map34['5'] = 5;
map34['6'] = 6;
map34['7'] = 7;
map34['8'] = 8;
map34['9'] = 9;
map34['a'] = 10;
map34['b'] = 11;
map34['c'] = 12;
map34['d'] = 13;
map34['e'] = 14;
map34['f'] = 15;
map34['g'] = 16;
map34['h'] = 17;
map34['i'] = 18;
map34['j'] = 19;
map34['k'] = 20;
map34['m'] = 21;
map34['n'] = 22;
map34['p'] = 23;
map34['q'] = 24;
map34['r'] = 25;
map34['s'] = 26;
map34['t'] = 27;
map34['u'] = 28;
map34['v'] = 29;
map34['w'] = 30;
map34['x'] = 31;
map34['y'] = 32;
map34['z'] = 33;
}
public double getLongitude() {
return longitude;
}
public double getLatitude() {
return latitude;
}
//
private int pow34(int i)
{
int sum = 1;
while(i > 0)
{
sum *= 34;
--i;
}
return sum;
}
//
private int Convert34to10(String str34)
{
int sum = 0;
for(int i = 0; i < str34.length(); ++i)
{
if( (str34.charAt(i) != 'l' && str34.charAt(i) != 'o') &&
((str34.charAt(i) >= '0' && str34.charAt(i) <= '9') ||
(str34.charAt(i) >= 'a' && str34.charAt(i) <= 'z'))
)
{
sum += map34[ str34.charAt(i)] * pow34(i);
}
else
{
System.out.println("invalid chaa");
return -1;
}
}
return sum;
}
//
public int Convert(String kcode)
{
if(kcode.length() != 9)
{
return -1;
}
int lut,lat;
char quad = kcode.charAt(0);
switch(quad)
{
case '5':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 105;
latitude = (double)lat / (3600 * 10) + 40;
break;
case '6':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 70;
latitude = (double)lat / (3600 * 10) + 40;
break;
case '7':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 70;
latitude = (double)lat / (3600 * 10) + 5;
break;
case '8':
lut = Convert34to10(kcode.substring(1, 5));
lat = Convert34to10(kcode.substring(5, 9));
longitude = (double)lut / (3600 * 10) + 105;
latitude = (double)lat / (3600 * 10) + 5;
break;
default:
}
return 0;
}
public static void main(String[] args) {
KCode code = new KCode();
code.Convert("8q91f4apv");
System.out.println(code.getLongitude());
System.out.println(code.getLatitude());
}
} 上述代码仅供参考。
相关文章推荐
- Google地图经纬度与平面坐标的相互转换、简单地图Demo
- 各地图gps坐标系统比较与转换以及经纬度距离计算MATLAB脚本
- 简简单单做地图-地址信息和经纬度坐标之间的转换
- Excel vba开发 合并单元格拆分自动填充功能、在每一条数据后面插入空白行、将地理坐标的经纬度转换成度等功能
- 地图经纬度及坐标系统转换的那点事
- 经纬度定义、经纬度格式、GDAL中地理坐标转换及地理坐标屏幕显示
- 经纬度转换地图坐标api示例代码
- 度分 格式 转换 GPS 经纬度定义、经纬度格式、GDAL中地理坐标转换及地理坐标屏幕显示
- GPS经纬度及谷歌地图坐标转换为百度地图坐标,解决地图显示经纬度的偏移问题
- 地图经纬度坐标与屏幕坐标的转换(android版)
- 经纬度坐标与地理像素坐标相互转换
- 经纬度坐标与地图容器像素坐标相互转换
- 经纬度定义、经纬度格式、GDAL中地理坐标转换及地理坐标屏幕显示
- 地理坐标、经纬度坐标与屏幕坐标的转换!
- iOS-地理坐标转换,原生地图获取的原始坐标转换为地图真实坐标
- 地图网站MapBar地理位置标记ID转换为经纬度的Javascript解密算法
- 百度地图根据地理坐标转换经纬度
- WGS84、GCJ02、BD09地图坐标系间的坐标转换及坐标距离计算
- ArcEngine下投影坐标和经纬度坐标的相互转换
- 经由过程百度地图API,将百度坐标转换成GPS经纬度