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 ...
随机推荐
- c#之反射总结
1.了解什么事程序集 2.加载程序集 首先要加载需要加载的程序集,然后找到指定的类型,进而往下进行动态加载. 要加载的程序集中的内容: public class Class1:Person { pr ...
- iOS VideoToolbox硬编H.265(HEVC)H.264(AVC):1 概述
本文档尝试用Video Toolbox进行H.265(HEVC)硬件编码,视频源为iPhone后置摄像头.去年做完硬解H.264,没做编码,技能上感觉有些缺失.正好刚才发现CMFormatDescri ...
- Django 学习笔记之一 环境搭建
以后的文章都是在windows系统进行的 首先下载安装Django包 方式1:使用 pip或easy_insatll来进行安装 同时按住win+R键,弹出命令行运行框输入,pip install Dj ...
- Feature Extraction
http://www.erogol.com/ml-work-flow-part-3-feature-extraction/
- mysql Host ‘XXXXXX’ is blocked because of many connection errors
mysql Host ‘XXXXXX’ is blocked because of many connection errors ERROR 1129 (00000): Host ‘XXXXXX’ i ...
- fork 函数 和vfork 函数的区别
问题描述: fork 函数 和vfork 函数的区别 问题解决: fork函数使用: 注: 以上printf 属于标准IO库带缓冲,如果标准输出链接到终端设备,则它是行 ...
- Centos——rpm和yum
间歇性的学习了centos的一些使用,发现一段时间不操作,就会忘掉其中的概念或者操作方式方法,于是在此总结一下. 一.问题描述 首先,把一个我最常忘记的概念性的东西在这里记录一下: 什么是yum,什么 ...
- MemSQL Start[c]UP 2.0 - Round 2 - Online Round
搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...
- 使用JAVA反射初始化数组(转)
在做JSON解析时,遇到了在不知道数组类型的前期下,需要转化为具体类型数组的问题.可以使用JAVA的反射来做. JSONArray jsonArray = (JSONArray) entry.getV ...
- jquery加入收藏代码
<html> <head> <script type="text/javascript" src="jquery-1.9.1.js" ...