This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resultStr=data.replace(/\ +/g,"");//去掉空格 | |
var resultStr=resultStr.replace(/[\r\n]/g,"");//去掉回车换行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GspModified { | |
final static double pi = 3.14159265358979324; | |
final static double a = 6378245.0; | |
final static double ee = 0.00669342162296594323; | |
public static void transform(double wgLat, double wgLon, double[] latlng) { | |
if (outOfChina(wgLat, wgLon)) { | |
latlng[0] = wgLat; | |
latlng[1] = wgLon; | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cmdi.util; | |
import java.io.File; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.GregorianCalendar; | |
import java.util.List; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//计算两个集合的差集 | |
public static List diff(List ls, List ls2) { | |
List list = new ArrayList(Arrays.asList(new Object[ls.size()])); | |
Collections.copy(list, ls); | |
list.removeAll(ls2); | |
return list; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 计算地图上两点之间的距离 | |
* @param longitude | |
* @param latitude | |
* @param long2 | |
* @param lat2 | |
* @return | |
*/ | |
public Double Distance(double longitude, double latitude, double long2, | |
double lat2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
最近做一个项目:需要查询一个站点(已知该站点经纬度)500米范围内的其它站点。所以,我首先想到的是,对每条记录,去进行遍历,跟数据库中的每一个点进行距离计算,当距离小于500米时,认为匹配。这样做确实能够得到结果,但是效率极其低下,因为每条记录都要去循环匹配n条数据,其消耗的时间可想而知。 | |
于是我就想到一个先过滤出大概的经纬度范围再进行计算。比方说正方形的四个点,于是我在网上搜索,意外的,查询到了一个关于这个计算附近地点搜索初探,里面使用python实现了这个想法。所以参考了一下原文中的算法,使用JAVA进行了实现。 | |
实现原理也是很相似的,先算出该点周围的矩形的四个点,然后使用经纬度去直接匹配数据库中的记录。 | |
思路:首先算出“给定坐标附近500米”这个范围的坐标范围。 虽然它是个圆,但我们可以先求出该圆的外接正方形,然后拿正方形的经纬度范围去搜索数据库。 | |
红色部分为要求的搜索范围,绿色部分我们能间接得到的结果范围 | |
先来求东西两侧的的范围边界。在haversin公式中令φ1 = φ2,可得 | |
用Java代码写就是 | |
//先计算查询点的经纬度范围lat已知纬度,lng已知经度 | |
double r = 6371;//地球半径千米 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//img.jsp页面 | |
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
<html> | |
<head> | |
<title>My JSP 'img.jsp' starting page</title> | |
</head> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.project.util; | |
import java.util.List; | |
public class Page<T> { | |
private int pageSize; | |
private int pageNum; | |
private int offSet; | |
private long totalPages; |