通过经纬度获取所属城市信息-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 ...
随机推荐
- 【UML】-NO.41.EBook.5.UML.1.001-【UML 大战需求分析】- 类图(Class Diagram)
1.0.0 Summary Tittle:[UML]-NO.41.EBook.1.UML.1.001-[UML 大战需求分析]- 类图 Style:DesignPattern Series:Desig ...
- 【LeetCode每天一题】Pascal's Triangle(杨辉三角)
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...
- Python3.6下使用会话session保持登陆状态
本次工具主要利用python easygui模块的inputbox让用户首次输入登陆信息,作为网站requests-post请求的data字段,观察XHR(异步加载)的数据包,构造post请求,利用r ...
- 基于jquery ajax的多文件上传进度条
效果图 前端代码,基于jquery <!DOCTYPE html> <html> <head> <title>主页</title> < ...
- Ubuntu下安装eclipse遇到的问题
今天在Ubuntu中安装eclipse时遇到如下问题: 解决方法: 打开eclipse安装目录下eclipse.ini文件 在文件最开头(注:一定是最开头)加上如下语句(-startup前面两行),第 ...
- Jenkins自动化构建(一)执行selenium+python脚本
Jenkins执行python写的selenium自动化脚本,通常会遇到,执行打不开浏览器,查看jenkins构建Console Output控制台输出信息,发现脚本是执行了的,但是出错了,打开浏览器 ...
- spring之拦截器
拦截器 实现HandlerInterceptor接口:注册拦截器<mvc:inteceptors> spring和springMVC父子容器的关系 在spring整体框架的核心概念中,容器 ...
- sqlserver字符集问题(中文出乱码,排序错误等)
在创建sqlserver 数据库时未指定排序字符集,databases则会使用instances的排序规则.为了支持中文,需要设置成Chinese_PRC_CI_AS. (1)通过sql脚本修改 -- ...
- [ Learning ] Spring Resources
1. Spring MVC Spring MVC原理及配置详解 springMVC系列之(三) spring+springMVC集成(annotation方式) Mybatis3+Spring4+Sp ...
- 水题T,二进制转16进制
输入一个2进制的数,要求输出该2进制数的16进制表示. 在16进制的表示中,A-F表示10-15 Input第1行是测试数据的组数n,后面跟着n行输入.每组测试数据占1行,包括一个以0和1组成的字符串 ...