租凭项目记录

来源:互联网 发布:js防水涂料是刚性的吗 编辑:程序博客网 时间:2024/04/28 08:56

1、百度地图两点距离

/**     * 计算两点之间距离     *      * @param start     * @param end     * @return 米     */    public double getDistance(double lat_a, double lng_a, double lat_b,            double lng_b) {        double pk = 180 / 3.14169;        double a1 = lat_a / pk;        double a2 = lng_a / pk;        double b1 = lat_b / pk;        double b2 = lng_b / pk;        double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);        double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);        double t3 = Math.sin(a1) * Math.sin(b1);        double tt = Math.acos(t1 + t2 + t3);        return 6366000 * tt;    }

2、list排序

package com.test1.listpaixu;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;public class maintest {    @SuppressWarnings("unchecked")    public static void main(String[] args) {        Student zlj = new Student("丁晓宇", 21);        Student dxy = new Student("赵四", 22);        Student cjc = new Student("张三", 11);        Student lgc = new Student("刘武", 19);        List<Student> studentList = new ArrayList<Student>();        studentList.add(zlj);        studentList.add(dxy);        studentList.add(cjc);        studentList.add(lgc);        Collections.sort(studentList, new SortByAge());        for (Student student : studentList) {            System.out.println(student.getName() + " / " + student.getAge());        }        System.out.println("  =  ");        Collections.sort(studentList, new SortByName());        for (Student student : studentList) {            System.out.println(student.getName() + " / " + student.getAge());        }    }}class SortByAge implements Comparator {    public int compare(Object o1, Object o2) {        Student s1 = (Student) o1;        Student s2 = (Student) o2;        if (s1.getAge() > s2.getAge())            return 1;        else if (s1.getAge() < s2.getAge()) {            return -1;        }        return 0;    }}class SortByName implements Comparator {    public int compare(Object o1, Object o2) {        Student s1 = (Student) o1;        Student s2 = (Student) o2;        return s1.getName().compareTo(s2.getName());    }}
0 0