小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

微信開發(fā)之如何根據(jù)經(jīng)緯度獲取所在的地點信息

 WindySky 2016-08-08

歡迎關(guān)注微信服務(wù)號:小灰熊   


package com.lwz.wx.util;

//需要導(dǎo)入的包 在網(wǎng)上都是比較容易找到的
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;






public class GetAddressbyJW {


/**
* @param args
*/


     //用來轉(zhuǎn)化URL 的 這里用的是百度的,其他的接口也都是類似的
 
public String palceRequestUrl(String lat,String lng) throws UnsupportedEncodingException { 
  
String url = "http://api.map.baidu.com/geocoder/v2/?"+ "&ak=" 
           + "百度給你的AK 需要設(shè)置為所以IP都可以用哦"+"&location="+lat+","+lng +"&output="+"json"+"&pois=0";  
return url;

}


     // 這里是獲取位置的

public String getPalace(String lat,String lng) throws Exception{ 
  String url = palceRequestUrl(lat,lng);  // 獲取完整的URL
  HttpClient client = new HttpClient();
  PostMethod getMethod = new PostMethod(url);
  client.executeMethod(getMethod);  // 用post方式提交數(shù)據(jù)

  String returnStr = getMethod.getResponseBodyAsString();//鏈接返回來的信息

         // 由于上面我們定義了接收返回的數(shù)據(jù)是JSON  所以這里需要對JSON 進行解析

  JSONObject jsonObj = JSONObject.fromObject(returnStr );// 把接收回來的轉(zhuǎn)成json

  // System.out.println(jsonObj);                                    //可以嘗試打印出來看下是什么
        String ss= jsonObj.getString("result");                      // 這個result 就是我們需要的結(jié)果
        JSONObject jsonObj1 = JSONObject.fromObject(ss);
       // System.out.println(jsonObj1);
        // System.out.println(jsonObj1.getString("formatted_address"));
         String message=jsonObj1.getString("addressComponent");
         JSONObject jsonObj2 = JSONObject.fromObject(message);         //這里就看你需要什么了 可以自己獲取
          message=jsonObj2.getString("city");
        //  System.out.println(message);
         return message;
         


    
    }

  // 簡單的main 調(diào)用


public static void main(String[] args) {
GetAddressbyJW test=new GetAddressbyJW();
try {
String ss= test.getPalace( "26.08", "119.28");
System.out.println(ss);
 
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
}


}



    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多