GPS坐标转百度坐标接口

GPS坐标转百度坐标接口

请求URL:

  • http://api.map.baidu.com/geoconv/v1/?coords=经度,纬度&from=1&to=5&ak=APPKEY

请求方式:

  • GET

返回示例

1
{"status":0,"result":[{"x":114.2307519546763,"y":29.57908428837437}]}
GPS坐标转百度坐标接口

百度地图接口

GPS坐标转百度坐标接口

请求URL:

  • http://api.map.baidu.com/geoconv/v1/?coords=经度,纬度&from=1&to=5&ak=APPKEY

请求方式:

  • GET

返回示例

1
{"status":0,"result":[{"x":114.2307519546763,"y":29.57908428837437}]}

地图检索

请求URL:

  • http://api.map.baidu.com/place/v2/search?query=key1$key2&location=经度,纬度&radius=2000&output=json&ak=APPKEY&page_size=20&page=0

请求方式:

  • GET

返回示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"status":0,
"message":"ok",
"total":176,
"results":[
{
"name":"北京银行ATM(广场西路)",
"location":{
"lat":39.914709,
"lng":116.402285
},
"address":"北京市东城区中华路4号中山公园南门",
"province":"北京市",
"city":"北京市",
"area":"东城区",
"street_id":"08db2caeab1dc6dcfb2213da",
"detail":1,
"uid":"08db2caeab1dc6dcfb2213da"
}
]
}

地标详情

请求URL:

  • http://api.map.baidu.com/place/v2/detail?uid=08db2caeab1dc6dcfb2213da&output=json&scope=2&ak=APPKEY

请求方式:

  • GET

返回示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"status":0,
"message":"ok",
"result":{
"uid":"08db2caeab1dc6dcfb2213da",
"street_id":"08db2caeab1dc6dcfb2213da",
"name":"北京银行ATM(广场西路)",
"location":{
"lng":116.40228495289,
"lat":39.914708526999
},
"address":"北京市东城区中华路4号中山公园南门",
"province":"北京市",
"city":"北京市",
"area":"东城区",
"detail_info":{
"tag":"金融;atm",
"navi_location":{
"lng":116.40393684689,
"lat":39.91399787517
},
"shop_hours":"00:00-24:00",
"brand":"北京银行",
"alias":[
""
],
"detail_url":"http://api.map.baidu.com/place/detail?uid=08db2caeab1dc6dcfb2213da&output=html&source=placeapi_v2",
"type":"life",
"overall_rating":"0.0",
"service_rating":"0",
"environment_rating":"0",
"image_num":"1"
},
"detail":1
}
}
百度地图接口

CentOS Docker 安装

安装

在 CentOS 6.5 以上使用 yum 安装 Docker

1
yum -y install docker-io

启动 Docker 后台服务

1
service docker start

测试运行 hello-world

1
docker run hello-world

如果本地没有 hello-world 这个镜像,会下载一个 hello-world 的镜像,并在容器内运行。

镜像加速

配置文件

1
/etc/docker/daemon.json

配置文件内容

1
2
3
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}

网易镜像地址

1
http://hub-mirror.c.163.com

阿里云镜像地址

1
https://dv8m3oe1.mirror.aliyuncs.com

修改配置后重启 Docker

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

Docker为什么刚运行就退出

docker 容器不是一个轻量级的虚拟机(vm),而是一个轻量级的终端(terminal):

1)它是一个只给你一次机会运行 shell 命令的终端

2)它是一个与其中运行的 shell 命令共存亡的终端(命令结束容器退出,命令运行容器运行)。

如何让docker容器在执行shell命令后不退出运行

使用 tail -f /dev/null 命令可以解决问题

如何登录容器环境

docker exec -it dockername /bin/bash

Ubantu 安装Docker

Ubuntu Docker
wget -qO- https://get.docker.com/ | sh
sudo service docker start

CentOS Docker 安装

Hexo 替换jQuery 源

Hexo 出现

1
GET http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js net::ERR_CONNECTION_RESET

替换jQuery源
在Hexo默认主题中,文件\themes\landscape\layout_partial\after-footer.ejs 以下代码:

1
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

替换成:

1
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

或百度源:

1
<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>
Hexo 替换jQuery 源

Java与Android组播收发程序实例

Java 组播收发程序实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package def;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class Multicast {

public static final int LOCAL_HOST_PORT = 1900;
public static final int DESTINATION_PORT = 1900;

public static final int DATA_LEN = 64 * 1024;
public static final String GROUP_ADDRESS = "239.255.255.250";

public static void main(String[] args) {
// 组播接收
new Thread(new Runnable() {
public void run() {
try {
receive();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();

// 组播发送
new Thread(new Runnable() {

@Override
public void run() {
try {
send();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

private static void receive() throws Exception {
InetAddress inetAddress = InetAddress.getByName(GROUP_ADDRESS);// 多播组
MulticastSocket multicastSocket = new MulticastSocket(LOCAL_HOST_PORT);// 新建一个socket,绑定接收端口1900
multicastSocket.joinGroup(inetAddress);// 加入多播组
while (true) {
byte[] inBuff = new byte[DATA_LEN];
DatagramPacket inPacket = new DatagramPacket(inBuff, inBuff.length);// 构造接收数据报,包含要接收的数据、长度
inPacket.setData(inBuff);
multicastSocket.receive(inPacket);// 接收数据报
System.out.println("onReceive: address = [" + inPacket.getAddress().toString() + "], port = ["
+ inPacket.getPort() + "], data = ["
+ new String(inPacket.getData(), inPacket.getOffset(), inPacket.getLength()) + "]");
}
}

private static void send() throws Exception {
int i = 0;
InetAddress group = InetAddress.getByName(GROUP_ADDRESS);
MulticastSocket multicastSocket = new MulticastSocket();
while (true) {
byte[] bytes = String.valueOf(++i).getBytes();
DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length, group, DESTINATION_PORT);// 发送数据报,指定目标端口和目标地址
multicastSocket.send(datagramPacket);
Thread.sleep(300);
}
}

如果是android程序,那么还需要加上以下部分:
(1)权限

1
2
3
4
5
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

(2)申请权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
   protected void setWiFiMulticastLock(boolean enable) {
if (multicastLock == null) {
multicastLock = wifiManager.createMulticastLock(getClass().getSimpleName());
}

if (enable) {
if (multicastLock.isHeld()) {
logger.w("WiFi multicast lock already acquired");
} else {
logger.i("WiFi multicast lock acquired");
multicastLock.acquire();
}
} else {
if (multicastLock.isHeld()) {
logger.i("WiFi multicast lock released");
multicastLock.release();
} else {
logger.w("WiFi multicast lock already released");
}
}
}

protected void setWifiLock(boolean enable) {
if (wifiLock == null) {
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, getClass().getSimpleName());
}
if (enable) {
if (wifiLock.isHeld()) {
logger.w("WiFi lock already acquired");
} else {
logger.i("WiFi lock acquired");
wifiLock.acquire();
}
} else {
if (wifiLock.isHeld()) {
logger.i("WiFi lock released");
wifiLock.release();
} else {
logger.w("WiFi lock already released");
}
}
}
Java与Android组播收发程序实例

EventBus 和 BroadcastReceiver 的区别

EventBus 和Android的 BroadcastReceiver/Intent 不同,EventBus 用了标准java类的事件,提供了更方便的API。当你要用很多case去区分事件时,EventBus很一个很好的解决方案,你不需要大量设置intent、给intent添加extras、实现大量broadcast receivers、再获得intent、从intent里提取数据。而且,EventBus 的开销低得多。

EventBus 和 BroadcastReceiver 的区别