项目中有用到了做个记录,需要的可以自己获取
public static Map<String, String> getlocation() {
URL url = null;
Map<String, String> map = new HashMap<String, String>();
HttpURLConnection connection = null;
String regEx = "[\n`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?自治区市省]";
try {
//腾讯IP定位(普通)接口 10,000次/日 5次/秒
url = new URL("http://apis.map.qq.com/ws/location/v1/ip?key=");//key需要https://lbs.qq.com/faq/serverFaq/webServiceKey获取key
connection = (HttpURLConnection) url.openConnection();// 新建连接实例
connection.setConnectTimeout(3000);