通过经纬度获取所属城市信息-php
测试经纬度信息,37.863036,113.598909。通过地图查询,所在城市为:阳泉。
<?php
class test{
public static $test_key = 'dfgfdgfh3c8ttrr1774gfdgfdgfd9rgqw1'; //这里是申请的百度appkey
$url = 'http://api.map.baidu.com/geocoder/v2/';
//37.863036
$longitude = number_format(doubleval($longitude), );
//113.598909
$latitude = number_format(doubleval($latitude), );
$gps = $latitude . ',' . $longitude;
$params = array(
'location' => $gps,
'pois' => ,
);
$info = test2::get_contents($url, $params);
print_r($info);
}
class test2{ private static function get_contents($url, $param)
{
$baidu_key = test::test_key ;
$param['ak'] = $baidu_key;
$param['output'] = 'json';
$url = $url . '?' . http_build_query($param, '', '&');
//echo $url;
$retry = ;
$result = array(); while ($retry > ) {
$result = json_decode(self::curl_get($url), true); if (!empty($result) && isset($result['status']) && $result['status'] == ) {
return $result;
}
if (!empty($result) && isset($result['status'])) {
$status = $result['status'];
} else {
$status = ' http_error:';
}
EdjLog::info("baidu_response retry status is" . $status.'params'.json_encode($param));
$retry--;
}
EdjLog::warning('request to baidu lbs api failed after retries'); return $result;
} private static function curl_get($url, $milliseconds = )
{
$start_time = microtime(true); $ch = curl_init();
//这个参数很重要,设置这个才可以支持毫秒级的超时设置
curl_setopt($ch, CURLOPT_NOSIGNAL, );
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_USERAGENT, self::$useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FAILONERROR, );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, self::$connecttimeout);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $milliseconds); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
$http_error_code = curl_errno($ch);
curl_close($ch); EdjLog::info("request to baidu lbs api, url is $url, cost time:" . (microtime(true) - $start_time));
EdjLog::info("baidu http_error:$http_error_code response is " . str_replace(PHP_EOL, '', $response));
return $response;
}
结果:
Array
(
[status] =>
[result] => Array
(
[location] => Array
(
[lng] => 113.598909
[lat] => 37.863036027778
) [formatted_address] => 山西省阳泉市城区德胜街130号
[business] =>
[addressComponent] => Array
(
[country] => 中国
[country_code] =>
[country_code_iso] => CHN
[country_code_iso2] => CN
[province] => 山西省
[city] => 阳泉市
[city_level] =>
[district] => 城区
[town] =>
[adcode] =>
[street] => 德胜街
[street_number] => 130号
[direction] => 北
[distance] =>
) [pois] => Array
(
) [roads] => Array
(
) [poiRegions] => Array
(
[] => Array
(
[direction_desc] => 内
[name] => 阳泉站
[tag] => 交通设施;火车站
[uid] => a2ef2cba1b2e6961ab0dd8da
[distance] =>
) ) [sematic_description] => 阳泉站内
[cityCode] =>
) )
通过经纬度获取所属城市信息-php的更多相关文章
- 根据百度API获得经纬度,然后根据经纬度在获得城市信息
package com.pb.baiduapi; import java.io.BufferedReader; import java.io.IOException; import java.io.I ...
- Java根据百度API获得经纬度,然后根据经纬度在获得城市信息
原文:http://www.open-open.com/code/view/1421032487812 import java.io.BufferedReader; import java.io.IO ...
- ios项目开发(天气预报项目):通过经纬度获取当前城市名称
1 . 在项目里加入� CoreLocation.framework 2 .在 .h 文件输入例如以下: 1.#import <CoreLocation/CLLocation.h> ...
- Python-根据照片信息获取用户详细信息(微信发原图或泄露位置信息)
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 蒙娜丽胖 PS:如有需要Python学习资料的小伙伴可以加点击下方 ...
- windows phone 7 定位(获取经纬度),然后找到经纬度所在的位置(城市信息)
原文:windows phone 7 定位(获取经纬度),然后找到经纬度所在的位置(城市信息) 前几天做项目用到, 代码贴给大家. /// <summary> /// 获取当前位置的经纬度 ...
- [微信小程序] 微信小程序获取用户定位信息并加载对应城市信息,wx.getLocation,腾讯地图小程序api,微信小程序经纬度逆解析地理信息
因为需要在小程序加个定位并加载对应城市信息 然而小程序自带api目前只能获取经纬度不能逆解析,虽然自己解析方式,但是同时也要调用地图,难道用户每次进小程序还要强行打开地图选择地址才定位吗?多麻烦也不利 ...
- 微信小程序自动定位,通过百度地图根据经纬度获取该地点所在城市信息
微信小程序获得经纬度 var that = this wx.getLocation({ type: 'wgs84', success(res) { console.log(res) that.setD ...
- 百度api:根据经纬度获取地理位置信息
调用百度api,根据经度和纬度获取地理位置信息,返回Json. C#代码: using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Syste ...
- JS根据经纬度获取地址信息
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
随机推荐
- MySQL--4操作数据表中的记录小结
最常用,最复杂的语句: 每一项的: 表的参照 From 条件 WHERE 进行记录的分组 GROUP BY 分组的时候对分组的条件进行设定 HAVING 对结果进行排序 ORDER BY ...
- webpack使用六
插件(Plugins) 插件(Plugins)是用来拓展Webpack功能的,它们会在整个构建过程中生效,执行相关的任务. Loaders和Plugins常常被弄混,但是他们其实是完全不同的东西,可以 ...
- mongodb对数组元素及内嵌文档进行增删改查操作(转)
from:https://my.oschina.net/132722/blog/168274 比如我有一个user类,他包含一个标签属性,这个标签是一个数组,数组里面的元素是内嵌文档,格式如下: &l ...
- jquery $.ajax $.get $.post的区别?
$.ajax 是 jQuery 底层 AJAX 实现,$.ajax是一种通用的底层封装,$.ajax()请求数据之后,则需要使用回调函数,有beforeSend.error.dataFilter.su ...
- install apache-activemq
进入bin/linux-x86-64下 cd apache-activemq-5.14.1/bin/linux-x86-64/ 启动 ./activemq start 五.启动成功后,访问 activ ...
- executing in nfs will not generate core dump file
最近遇到了一个奇怪的问题. linux系统的pc搭建nfs server,开发板作为nfs client,开发板中全程root权限操作,执行的程序放到 nfs server 中 exports 出的目 ...
- Python全栈-网络编程-TCP粘包
一.什么是TCP粘包 C/S架构下,接收方不知道每个消息的发送间隙.也不知道每次应该提取多少个字节的数据,与此同时,TCP是面向连接的,面向流的,收发两端都要有,因此发送端为了将多个发往接收端的数据包 ...
- 标准I/O流
一.标准输入流 标准输入流对象cin,重点掌握的函数 cin.get() //一次只能读取一个字符 cin.get(一个参数) //读一个字符 cin.get(三个参数) //可以读字符串 cin.g ...
- Marlin 溫度感應器 數值轉換對應表
Marlin 溫度感應器 數值轉換對應表 (2014/03/27)Update: 自己實測了這個自動產生的對應表,結果測得的溫度與實際值仍有相當大的誤差.看來還是要回頭用測量的方式來校正溫度... ...
- spring boot: ConfigurationProperties
读取配置信息 1.5 之前 @Component @ConfigurationProperties(prefix = "user", locations= {"class ...