zoukankan      html  css  js  c++  java
  • java------4.根据经纬度排序,并计算距离。。。。。。。。根据地址计算出经纬度

    
    
    select xs.*,sqrt ((((118.9136869871-xs.qps_log)*PI()*12656*COS(((32.0842566206+xs.qps_lat)/2)*PI()/180)/180)*((118.9136869871-xs.qps_log)*PI()*12656*COS(((32.0842566206+xs.qps_lat)/2)*PI()/180)/180))+( ((118.9136869871-xs.qps_lat)*PI()*12656/180)*((32.0842566206-xs.qps_lat)*PI()*12656/180) ) ) as juli from t_qps xs
    
    
    

      


    1
    String sql = "select xm.*,xs.*,xs.id as shopId,sqrt ( ( (( " + customerLongitude 2 + "-xs.longitude)*PI()*12656*COS(((" + customerLatitude 3 + "+xs.latitude)/2)*PI()/180)/180)" + "*" + "(( " 4 + customerLongitude + "-xs.longitude)*PI()*12656*COS(((" 5 + customerLatitude + "+xs.latitude)/2)*PI()/180)/180) " + ")" 6 + "+(" + " (( " + customerLatitude 7 + "-xs.latitude)*PI()*12656/180) " + "*" + "((" + customerLatitude 8 + "-xs.latitude)*PI()*12656/180)" + " )" + " ) as juli "; 9 10 11 double LonB = Double.parseDouble(m.get("longitude").toString()); 12 double LatB = Double.parseDouble(m.get("latitude").toString()); 13 double distance = Math.floor(XiNaiInterfaceUtils.getDistance(customerLongitude,customerLatitude, LonB, LatB) / 1000*10)/10;

    计算经纬度 需要 commons-lang3-3.1.jar 

     1 import java.io.BufferedReader;  
     2 import java.io.IOException;  
     3 import java.io.InputStreamReader;  
     4 import java.net.URL;  
     5 import java.net.URLEncoder;  
     6 import java.util.HashMap;  
     7 import java.util.Map;  
     8 
     9 import org.apache.commons.lang3.StringUtils;
    10 /**
    11  *经纬度
    12  * @author Administrator
    13  *
    14  */
    15 public class LantiDemo {
    16 
    17     public static final String KEY_1 = "7d9fbeb43e975cd1e9477a7e5d5e192a";  
    18 
    19     public static Map<String,String> getGeocoderLatitude(String address){  
    20         BufferedReader in = null;  
    21         try {  
    22             address = URLEncoder.encode(address, "UTF-8");  
    23             URL tirc = new URL("http://api.map.baidu.com/geocoder?address="+ address +"&output=json&key="+ KEY_1);  
    24 
    25 
    26             in = new BufferedReader(new InputStreamReader(tirc.openStream(),"UTF-8"));  
    27             String res;  
    28             StringBuilder sb = new StringBuilder("");  
    29             while((res = in.readLine())!=null){  
    30                 sb.append(res.trim());  
    31             }  
    32             String str = sb.toString();  
    33             Map<String,String> map = null;  
    34             if(StringUtils.isNotEmpty(str)){  
    35                 int lngStart = str.indexOf("lng":");  
    36                 int lngEnd = str.indexOf(","lat");  
    37                 int latEnd = str.indexOf("},"precise");  
    38                 if(lngStart > 0 && lngEnd > 0 && latEnd > 0){  
    39                     String lng = str.substring(lngStart+5, lngEnd);  
    40                     String lat = str.substring(lngEnd+7, latEnd);  
    41                     map = new HashMap<String,String>();  
    42                     map.put("lng", lng);  
    43                     map.put("lat", lat);  
    44                     return map;  
    45                 }  
    46             }  
    47         }catch (Exception e) {  
    48             e.printStackTrace();  
    49         }finally{  
    50             try {  
    51                 in.close();  
    52             } catch (IOException e) {  
    53                 e.printStackTrace();  
    54             }  
    55         }  
    56         return null;  
    57     }  
    58 
    59     public static void main(String args[]){  
    60         try {  
    61             Map<String, String> json = LantiDemo.getGeocoderLatitude("南京市栖霞区仙隐北路5号");  
    62             System.out.println("lng : " + json.get("lng"));  
    63             System.out.println("lat : " + json.get("lat"));  
    64         }catch (Exception e ){  
    65             e.printStackTrace();  
    66         }  
    67     }  
    68 }
  • 相关阅读:
    Aerospike系列:4:简单的增删改查aql
    Aerospike系列:3:aerospike特点分析
    MySQL事物系列:2:事物的实现
    MySQL事物系列:1:事物简介
    MySQL 源码系列:1:窥探篇
    MySQL 内存和CPU优化相关的参数
    Aerospike系列:2:商业版和社区版的比较
    Aerospike系列:1:安装
    MDX Cookbook 08
    MDX Cookbook 07
  • 原文地址:https://www.cnblogs.com/coriander/p/6530374.html
Copyright © 2011-2022 走看看