0
点赞
收藏
分享

微信扫一扫

根据手机号码查归属的再查经纬度

ivy吖 2022-07-28 阅读 54



 

public class LngAndLatUtil
{
public static Map<String, String> getCityNameByPhone(String phone)throws Exception
{
Map<String, String> map = new HashMap<String, String>();
String url = ApplicationConst.PHONE_TO_CITY_PAIPAI + phone;
String json = loadJSON(url);
json=json.replace("(", "").replace(")", "").replace(";", "").substring(0, json.indexOf("<")-3);
JSONObject obj = JSONObject.parseObject(json);

{
String cityName = obj.getString("cityname");
String province = obj.getString("province");
map.put("cityName", cityName);
map.put("province", province);
}

return map;
}

public static Map<String,String> getLngLatByPhone(String phone)throws Exception{
String city=getCityNameByPhone(phone).get("cityName");

String url = ApplicationConst.CITY_TO_LAT_LON_BAIDU + "&ak="+ApplicationConst.BAIDU_AK+"&city="+city+"&address="+city;
String json = loadJSON(url);

JSONObject obj = JSONObject.parseObject(json);
JSONObject location=obj.getJSONObject("result").getJSONObject("location");
Map<String,String> latLng=Maps.newHashMap();
latLng.put("lat", location.getString("lat"));
latLng.put("lng", location.getString("lng"));
return latLng;
}

private static String loadJSON(String url)throws Exception
{
StringBuilder json = new StringBuilder();
try
{
URL oracle = new URL(url);
URLConnection urlConn = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream(),"GBK"));
String inputLine = null;
while ((inputLine = in.readLine()) != null)
{
json.append(new String(inputLine));
}
in.close();
}
catch (IOException e)
{
throw e;
}
return json.toString();
}



public static void main(String[] args)throws Exception
{
System.out.println(getLngLatByPhone("18868716531").get("lat"));
}
}

public static final String PHONE_TO_CITY_TAOBAO="http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=";
public static final String PHONE_TO_CITY_HAO_SERVICE="http://apis.haoservice.com/mobile";
public static final String PHONE_TO_CITY_PAIPAI="http://virtual.paipai.com/extinfo/GetMobileProductInfo?amount=10000&mobile=";
public static final String CITY_TO_LAT_LON_BAIDU="http://api.map.baidu.com/geocoder/v2/?output=json";

根据手机号码查归属的再查经纬度

举报

相关推荐

0 条评论