Android开发之火星坐标转换工具
代码:
import java.io.InputStream;
import java.io.ObjectInputStream; /*
* 把获取到的真实地址转换为火星坐标
*/
public class LocationUtils { public static double[] standardToChina(Double x, Double y) { try {
double[] haha = new double[2];
PointDouble pointDouble = new PointDouble(x, y);
PointDouble s2c = ModifyOffset.getInstance(
ModifyOffset.class.getResourceAsStream("axisoffset.dat"))
.s2c(pointDouble);
haha[0] = s2c.x;
haha[1] = s2c.y;
return haha;
} catch ( Exception e ) {
e.printStackTrace();
} return null; } static class ModifyOffset {
private static ModifyOffset modifyOffset;
static double[] X = new double[660 * 450];
static double[] Y = new double[660 * 450]; private ModifyOffset(InputStream inputStream) throws Exception {
init(inputStream);
} public synchronized static ModifyOffset getInstance(InputStream is)
throws Exception {
if ( modifyOffset == null ) {
modifyOffset = new ModifyOffset(is);
}
return modifyOffset;
} public void init(InputStream inputStream) throws Exception {
ObjectInputStream in = new ObjectInputStream(inputStream);
try {
int i = 0;
while ( in.available() > 0 ) {
if ( (i & 1) == 1 ) {
Y[(i - 1) >> 1] = in.readInt() / 100000.0d;
;
} else {
X[i >> 1] = in.readInt() / 100000.0d;
;
}
i++;
}
} finally {
if ( in != null )
in.close();
}
} // standard -> china
public PointDouble s2c(PointDouble pt) {
int cnt = 10;
double x = pt.x, y = pt.y;
while ( cnt-- > 0 ) {
if ( x < 71.9989d || x > 137.8998d || y < 9.9997d || y > 54.8996d )
return pt;
int ix = (int) (10.0d * (x - 72.0d));
int iy = (int) (10.0d * (y - 10.0d));
double dx = (x - 72.0d - 0.1d * ix) * 10.0d;
double dy = (y - 10.0d - 0.1d * iy) * 10.0d;
x = (x + pt.x + (1.0d - dx) * (1.0d - dy) * X[ix + 660 * iy] + dx
* (1.0d - dy) * X[ix + 660 * iy + 1] + dx * dy
* X[ix + 660 * iy + 661] + (1.0d - dx) * dy
* X[ix + 660 * iy + 660] - x) / 2.0d;
y = (y + pt.y + (1.0d - dx) * (1.0d - dy) * Y[ix + 660 * iy] + dx
* (1.0d - dy) * Y[ix + 660 * iy + 1] + dx * dy
* Y[ix + 660 * iy + 661] + (1.0d - dx) * dy
* Y[ix + 660 * iy + 660] - y) / 2.0d;
}
return new PointDouble(x, y);
} // china -> standard
public PointDouble c2s(PointDouble pt) {
int cnt = 10;
double x = pt.x, y = pt.y;
while ( cnt-- > 0 ) {
if ( x < 71.9989d || x > 137.8998d || y < 9.9997d || y > 54.8996d )
return pt;
int ix = (int) (10.0d * (x - 72.0d));
int iy = (int) (10.0d * (y - 10.0d));
double dx = (x - 72.0d - 0.1d * ix) * 10.0d;
double dy = (y - 10.0d - 0.1d * iy) * 10.0d;
x = (x + pt.x - (1.0d - dx) * (1.0d - dy) * X[ix + 660 * iy] - dx
* (1.0d - dy) * X[ix + 660 * iy + 1] - dx * dy
* X[ix + 660 * iy + 661] - (1.0d - dx) * dy
* X[ix + 660 * iy + 660] + x) / 2.0d;
y = (y + pt.y - (1.0d - dx) * (1.0d - dy) * Y[ix + 660 * iy] - dx
* (1.0d - dy) * Y[ix + 660 * iy + 1] - dx * dy
* Y[ix + 660 * iy + 661] - (1.0d - dx) * dy
* Y[ix + 660 * iy + 660] + y) / 2.0d;
}
return new PointDouble(x, y);
} } static class PointDouble {
double x, y; PointDouble(double x, double y) {
this.x = x;
this.y = y;
} public String toString() {
return "x=" + x + ", y=" + y;
}
} }
Android开发之火星坐标转换工具的更多相关文章
- Android开发之使用sqlite3工具操作数据库的两种方式
使用 sqlite3 工具操作数据库的两种方式 请尊重他人的劳动成果,转载请注明出处:Android开发之使用sqlite3工具操作数据库的两种方式 http://blog.csdn.net/feng ...
- Android开发之常用必备工具类图片bitmap转成字符串string与String字符串转换为bitmap图片格式
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 博客园主页:http://www.cnblogs.com/mcxiaobing ...
- [Android开发学iOS系列] 工具篇: Xcode使用和快捷键
[Android开发学iOS系列] 工具篇: Xcode使用和快捷键 工欲善其事必先利其器. 编辑 Cmd + N: 新建文件 Option + Cmd + N: 新建文件夹 Cmd + / : 注释 ...
- Android 开发环境搭建以及工具(不断更新)
学习android需要学习的编程知识 https://wiki.cyanogenmod.org/w/Doc:_Development_Resources 从http://source.android. ...
- Android开发之《常用工具及文档汇总》
GreenVPN:https://www.getgreenjsq.com/ Android开发工具.资料下载汇总:http://androiddevtools.cn/#img-size-handle- ...
- Android开发专业名词及工具概述
前言: 系统的学习下Android开发中涉及到的一些专业名词 和Android开发工具 名词: 一.SDK(Software Development Kit) 软件开发工具包:一般都是一些软件工程师为 ...
- 几款Android开发人员必备小工具
在这里我介绍一下我常常在Android Studio里面使用的小工具吧,这些工具都能够在plugin里面搜索到. (当然了哈.我也是从网上找的.用着挺方便的,在这里总结一下) Gsonformat: ...
- Android开发中的logcat工具使用
http://os.51cto.com/art/200905/126051.htm 用adb直接查看log: adb logcat 清除之前的log: adb logcat -c 加过滤查看lo ...
- Android开发免费类库和工具集合
用于Android开发的免费类库和工具集合,按目录分类. Action Bars ActionBarSherlock Extended ActionBar FadingActionBar GlassA ...
随机推荐
- 调皮的转义之addslashes
背景: php自5.3版本开始废除set_magic_quotes_runtime函数,并在5.4及以后版本中移除了该函数 今天程序在向mysql插入一个serialize序列化后的数组时,由于一个数 ...
- zip压缩包密码破解
有一种破解方法叫做Known plaintext attack.市面上的密码破解软件几乎都带有这个功能.操作方法就是找到加密压缩包中的任意一个文件,用同样的压缩软件同样的压缩方式压缩成一个不加密的包, ...
- Careercup - Facebook面试题 - 5188884744896512
2014-05-02 07:18 题目链接 原题: boolean isBST(const Node* node) { // return true iff the tree with root 'n ...
- HTML+CSS入门
<strong>加粗</strong> <em>斜体</em> <p>段落</p> <span>设置单独样式< ...
- System.IO.StreamWriter
string path = @"D:\a.txt"; System.IO.StreamWriter swOut = new System.IO.StreamWriter(path, ...
- BZOJ3473: 字符串
3473: 字符串 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 109 Solved: 47[Submit][Status] Descriptio ...
- C#文件对话框,一次多选文件设置
OpenFileDialog ofd = new OpenFileDialog();ofd.Multiselect = true;if (ofd.ShowDialog() == DialogResul ...
- Remote Desktop manager 连接后无法自动登录
现象: Remote Desktop manager 连接后无法自动登录 用Windows 自带的远程桌面 可以自动登录 解决方法: 在指定站点 右键 Edit Entry. 如下图处打勾就可以了.
- Consumer Client Re-Design (翻译)
注:0.9版本Kafka的一个重大改变就是consumer和producer API的重新设计. 这篇Kafka的文档大致介绍了对于consumer API重新设计时想要实现的功能.0.9版本的确实现 ...
- Unity3d Android程序嵌入Admob广告条
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140441353482/ Seems like using a simple A ...