4字节 经纬度_java 获取本机经纬度

package com.smm.web.mtower.util;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.net.URL;

/**

* Created by zhenghao on 2016/6/24.

* 当前位置处理工具

*/

public class LocationUtil {

/**

* 获取指定IP对应的经纬度(为空返回当前机器经纬度)

* @return

*/

public static String[] getIPXY() {

//获取本机公网ip

String ip = getPublicWebIP();

if(ip==null || ip.trim().equals("")) return null;

//百度map ak

String ak = "TjoQT*****************Bj8jV";

try {

URL url = new URL("http://api.map.baidu.com/location/ip?ak=" + ak + "&ip=" + ip + "&coor=bd09ll");

InputStream inputStream = url.openStream();

InputStreamReader inputReader = new InputStreamReader(inputStream);

BufferedReader reader = new BufferedReader(inputReader);

StringBuilder sb = new StringBuilder();

String str;

do {

str = reader.readLine();

sb.append(str);

} while (null != str);

str = sb.toString();

if (str.isEmpty()) {

return null;

}

// 获取坐标位置

int index = str.indexOf("point");

int end = str.indexOf("}}", index);

if (index == -1 || end == -1) {

return null;

}

str = str.substring(index - 1, end + 1);

if (str.isEmpty()) {

return null;

}

String[] ss = str.split(":");

if (ss.length != 4) {

return null;

}

String x = ss[2].split(",")[0];

String y = ss[3];

x = x.substring(x.indexOf("\"") + 1, x.indexOf("\"", 1));

y = y.substring(y.indexOf("\"") + 1, y.indexOf("\"", 1));

return new String[] { x, y };

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

public static String getPublicWebIP() {

String http_url ="http://www.ip.cn/";

try{

URL url = new URL(http_url);

InputStream inputStream = url.openStream();

InputStreamReader inputReader = new InputStreamReader(inputStream);

BufferedReader reader = new BufferedReader(inputReader);

StringBuilder sb = new StringBuilder();

String str;

do {

str = reader.readLine();

sb.append(str);

} while (null != str);

str = sb.toString();

if (str.isEmpty()) {

return null;

}

//从内容中截取代码 117.184.120.234

int start = str.indexOf("") + "".length();

int end = str.indexOf("");

str = str.substring(start,end);

return str;

}catch (Exception e){

e.printStackTrace();

}

return null;

}

public static void main(String[] args) {

String [] location = LocationUtil.getIPXY();

assert location != null;

String widu=location[1];

String jndu=location[0];

System.out.println(widu);

System.out.println(jndu);

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420330.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C#秘密武器之反射——基础篇

先来一段有用的反射代码 namespace Calculator { public interface Iwel { String Print(); } } namespace Calculator { public class Arithmetic:Iwel { /// <summary> /// 没有带参数的构造函数 /// </summary> public Arithmetic() {} public Arithmetic(i…

python社区版可以用库么_应用Python,你不但能够得到出色的小区适用和普遍的库集...

哪样计算机语言最好是&#xff1f;这个问题很有可能始终不容易找答案。萝卜青菜&#xff0c;各有所好&#xff0c;AI技术工程师和生物学家能够依据新项目必须&#xff0c;从诸多计算机语言中挑选最合适自身的。选Python還是选Java?2020年&#xff0c;顶级程序猿最应当把握的7种…

Python3 etree, requests库抓取bt

bt种子抓取1. 抓取你想要的数据2. 爬取bt种子3. 抓取磁力链迷上了追番.. . bt种子xunlei来解决。 推荐一个网站https://mikanani.me。可以搜索你想要的动漫… 以bt的形式下载&#xff0c;或者复制磁力链。 1. 抓取你想要的数据 需要了解requests, etree库&#xff0c;etree用…

ecshop各个文件夹作用

Images文件夹&#xff1a;这个文件夹下有子文件夹&#xff0c;在这些子文件夹下面存放着当前网站商品的原始图片和缩略图。这些子文件夹命名有规律的&#xff0c;它们的文件名是它们目录下商品加入 的年月份。也就是说在同一个月份加入的商品&#xff0c;它们的图片是在同一个文…

unity2018关联不到vs_现实VS真爱:远嫁的幸福和悲哀

陆拾一 LUSHIYI《现实VS真爱&#xff1a;远嫁的幸福和悲哀》Part.1你有过远嫁的犹豫或者经历吗&#xff1f;关于这个话题&#xff0c;我从未写过。今天借着一封读者的来信&#xff0c;与大家聊一聊。拾一&#xff0c;你好。我跟男朋友在一起两年了&#xff0c;现在到了谈婚论嫁…

dubbo使用nacos作为注册中心

spring-cloud nacos dubbodubbo接口服务提供者消费者&#xff0c;要订阅对应的服务&#xff0c;订阅提供者使用openFeign以http为协议进行rest调用。而dubbo是tcpport&#xff0c;使用tcp协议的。 版本说明 dubbo : 2.7.8 spring-cloud-alibaba: 2.1.4.RELEASE spring-cloud:…

vim下php文件中自动缩排html代码

问题&#xff1a;vim下怎样在php文件中通过 命令自动缩排html代码&#xff1f;解决&#xff1a;1、先说下html自动缩排 我的vim是7.4版本&#xff0c;已经包含了html.vim之类的缩排插件&#xff0c;但是缩排的时候<body> <head> 没有进行缩排 在.vimrc中加入如下代…

lgg8配置_LGG8XThinQ参数配置-LG G8X ThinQ详细性能评测

LG G8X ThinQ是一款全新发布的机型&#xff0c;这款手机和iPhone12一样不赠送充电器&#xff0c;那么这款手机的参数配置是什么&#xff1f;有哪些值得入手的地方&#xff1f;小编为大家带来最新的手机性能评测&#xff0c;快来看看吧。一、参数配置手机型号LG G8X ThinQ手机屏…

关于go指针在方法or函数中这件事

title1. go中的指针2. 函数中的指针3. 方法中的指针1. go中的指针 使用 *类型 声明指针… 使用*变量名获取指针的值… 使用 &p 获取指针的内存地址… fmt.Println(" 指针复习 ")// 声明指针avar a *intb : 1// 获取到b的内存地址.. 指向ba &bfmt.Println(a…

前端学习(1331):mongoose第三方模块

const mongoose require(mongoose); mongoose.connect(mongodb://localhost/playground, { useUnifiedTopology: true }).then(() > console.log(数据库连接成功)).catch(err > console.log(err, 数据库连接失败)) 运行结果

MySQL在大型网站的应用架构演变

http://www.csdn.net/article/2014-06-10/2820160 -- 原文地址 转载于:https://www.cnblogs.com/thrillerz/p/4215150.html

ikbc机械键盘打字出现重复_双十一机械键盘优惠清单,阿米洛/ikbc/吉利鸭/杜咖/美商海盗船/雷神/Filco机械键盘推荐...

这次为大家带来的是一篇双十一机械键盘的优惠汇总清单&#xff0c;其中杜咖的优惠力度较大&#xff0c;高斯的性价比很高&#xff0c;然后阿米洛则推出了好几款双十一限定款&#xff0c;我们一起来看看吧~TOP1、罗技&#xff08;Logitech&#xff09;K835原价&#xff1a;369元…

前端学习(1333):mongodb增

const mongoose require(mongoose); mongoose.connect(mongodb://localhost/playground, { useUnifiedTopology: true }).then(() > console.log(数据库连接成功)).catch(err > console.log(err, 数据库连接失败))//创建集合规则 const courseSchema new mongoose.Sche…

Exception in thread “main“ java.lang.IllegalStateException: Duplicate key xxx

debug..hah… 这个错误是使用stream流把list收集成map搞的&#xff0c;原因是map的key是唯一的&#xff0c;如果不唯一就抛出了这个异常。 下面是异常代码 import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors;/*…

Http方法:Get请求与Post请求的区别

Get是向服务器发索取数据的一种请求&#xff0c;而Post是向服务器提交数据的一种请求Get是获取信息&#xff0c;而不是修改信息&#xff0c;类似数据库查询功能一样&#xff0c;数据不会被修改Get请求的参数会跟在url后进行传递&#xff0c;请求的数据会附在URL之后&#xff0c…

前端学习(1332):mongodb安装

一、安装 双击安装文件&#xff0c;然后安装指引点击下一步 ​​ 选择【Custom】安装类型 ​​ 将程序安装到D盘MongoDB目录下&#xff08;如果切换了目录&#xff0c;记得对应调整monggo.bat下面的路径&#xff09; ​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​…

华为手机什么时候更新鸿蒙系统_华为鸿蒙系统什么时候能超过iOS、安卓?任正非表态了...

众所周知&#xff0c;自从去年8月份华为高调发布了鸿蒙系统之后&#xff0c;网友们每时每刻都在盼望着鸿蒙系统能够取代安卓&#xff0c;成为华为手机使用的操作系统。甚至还有人觉得以华为的能力&#xff0c;鸿蒙一出&#xff0c;能够迅速超过苹果的iOS和安卓系统。可惜原来余…