Package com.wangku.was.utils;
Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
Import Java.net.URL;
Import java.net.URLConnection;
Import Net.sf.json.JSONObject;
/**
* Get the user's geographic location based on latitude and longitude values
* @ClassName: Latitudeutil
* @author Zhangmeijie
* @date 2015-6-29 1:44:44
* @exception
* @since 1.0
*/
public class Latitudeutil {
/**
* @Title: GEOCODEADDR
* @param latitude Latitude
* @param longitude Longitude
* @return
* @author Zhangmeijie
* @date 2015-6-29 1:42:24
* @exception
* @since 1.0
*/
@SuppressWarnings ("Static-access")
public static string Getaddressbylatandlon (string latitude, string longitude) {
String address = null;
String url = String.Format ("http://api.map.baidu.com/geocoder/v2/?ak=pmCgmADsAsD9rEXkqWNcTzjd&location=%s,%s &output=json&pois=1 ", latitude, longitude);
try {
URL myurl = new URL (URL);
URLConnection httpsconn = (urlconnection) myurl.openconnection ();
if (httpsconn! = null) {
InputStreamReader INSR = new InputStreamReader (Httpsconn.getinputstream (), "UTF-8");
BufferedReader br = new BufferedReader (INSR);
String data = null;
StringBuffer sb = new StringBuffer ("");
while ((data = Br.readline ()) = null) {
Sb.append (data);
}
Jsonobject jsonobject = new Jsonobject (). Fromobject (Sb.tostring ());
Address = Jsonobject.getjsonobject ("result"). GetString ("formatted_address");
Insr.close ();
} else {
return null;
}
} catch (Exception e) {
E.printstacktrace ();
return null;
}
return address;
}
/**
* Test method
* @Title: Main
* @param
* @return
* @author Zhangmeijie
* @date 2015-6-29 1:44:50
* @exception
* @since 1.0
*/
public static void Main (string[] args) {
String addr = Getaddressbylatandlon ("22.53836564", "114.02681090");//Latitude Longitude
System.out.println (addr);
}
}
Provider-java obtaining a user's geographic location based on latitude and longitude values