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 ...
随机推荐
- 微信/QQ机器人的实现
介绍: Mojo-Webqq和Mojo-Weixin是在github上基于webQQ和网页版WeiXin,用Perl语言实现的开源的客户端框架,它通过插件提供基于HTTP协议的api接口供其他语言或系 ...
- ASP.NET MVC 学习第一天
今天开始第一天学习asp.net mvc,写的不是很好,高手不要喷,希望大家能一起进步学习. 好了,开始学习 新建项目,选择mvc 4应用程序 接下来选择基本,视图引擎当然要选择Razor,如果在选择 ...
- html笔记 仅适用于个人
如何使图片与文本框上下对齐 其实就给<img>加一个属性 align="absmiddle" <form method="post" acti ...
- VBS基础篇 - 队列
VBS中的队列需要使用System.Collections.Queue '建立队列 Dim Que : Set Que = CreateObject("System.Collections. ...
- 《C++Primer》复习——with C++11 [2]
1.数组引用形参,C++允许将变量定义成数组的引用,给予同样的道理,形参也可以是数组的引用,此时引用形参绑定到对应的实参上,也就是绑定到数组上 ]) { for (auto elem : arr) c ...
- 【POJ】【2960】S-Nim
博弈论 这题跟 BZOJ 1874 取石子游戏 差不多 先暴力求出10000以内的SG函数(利用定义来求即可) 然后每次询问直接将SG值异或起来即可…… Source Code Problem: Us ...
- [CF]codeforces round#366(div2)滚粗记
开场心理活动:啊打完这场大概有1700了吧 中途心理活动:啊这个ABC看起来都随便做啊 死亡原因:欸怎么没网了 -75 .. A [题意]Hulk说完一句I hate会说that I love 然后是 ...
- Memcached 安装及配置
下载Memcached.exe 保存到c:\memcached 运行command: 输入 c:\memcached\memcached.exe -d install 回车,安装memcached s ...
- MoveManager管理类
MoveManager:移动管理类 struct MoveOpt { int cur_seq; ObjecInfo* obj; }; std::map<ObjID, MoveOpt> m_ ...
- 关于asp.net mvc4 在IE8下 导出excel失败的解决办法
在使用FileResult向浏览器输出文件时(pdf,excel等),通常这样做: byte[] fileContents = Encoding.UTF8.GetBytes(sbHtml.ToStri ...