测试经纬度信息,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的更多相关文章

  1. 根据百度API获得经纬度,然后根据经纬度在获得城市信息

    package com.pb.baiduapi; import java.io.BufferedReader; import java.io.IOException; import java.io.I ...

  2. Java根据百度API获得经纬度,然后根据经纬度在获得城市信息

    原文:http://www.open-open.com/code/view/1421032487812 import java.io.BufferedReader; import java.io.IO ...

  3. ios项目开发(天气预报项目):通过经纬度获取当前城市名称

     1 . 在项目里加入� CoreLocation.framework 2 .在 .h 文件输入例如以下: 1.#import <CoreLocation/CLLocation.h> ...

  4. Python-根据照片信息获取用户详细信息(微信发原图或泄露位置信息)

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 蒙娜丽胖 PS:如有需要Python学习资料的小伙伴可以加点击下方 ...

  5. windows phone 7 定位(获取经纬度),然后找到经纬度所在的位置(城市信息)

    原文:windows phone 7 定位(获取经纬度),然后找到经纬度所在的位置(城市信息) 前几天做项目用到, 代码贴给大家. /// <summary> /// 获取当前位置的经纬度 ...

  6. [微信小程序] 微信小程序获取用户定位信息并加载对应城市信息,wx.getLocation,腾讯地图小程序api,微信小程序经纬度逆解析地理信息

    因为需要在小程序加个定位并加载对应城市信息 然而小程序自带api目前只能获取经纬度不能逆解析,虽然自己解析方式,但是同时也要调用地图,难道用户每次进小程序还要强行打开地图选择地址才定位吗?多麻烦也不利 ...

  7. 微信小程序自动定位,通过百度地图根据经纬度获取该地点所在城市信息

    微信小程序获得经纬度 var that = this wx.getLocation({ type: 'wgs84', success(res) { console.log(res) that.setD ...

  8. 百度api:根据经纬度获取地理位置信息

    调用百度api,根据经度和纬度获取地理位置信息,返回Json. C#代码: using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Syste ...

  9. JS根据经纬度获取地址信息

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

随机推荐

  1. 【Java】-NO.17.EBook.4.Java.1.014-【疯狂Java讲义第3版 李刚】- Annotation

    1.0.0 Summary Tittle:[Java]-NO.17.EBook.4.Java.1.014-[疯狂Java讲义第3版 李刚]-  Annotation Style:EBook Serie ...

  2. python 常见报错汇总

    python官方文档:https://docs.python.org/zh-cn/3/tutorial/index.html 1.indentationerror:unindent does not ...

  3. [LeetCode] 系统刷题5_Dynamic Programming

    Dynamic Programming 实际上是[LeetCode] 系统刷题4_Binary Tree & Divide and Conquer的基础上,加上记忆化的过程.就是说,如果这个题 ...

  4. ie8以下兼容圆角等css3的属性

    <!--[if lt IE 10]> <script type="text/javascript" src="PIE.js"></ ...

  5. mysql 增加列,修改列名、列属性,删除列语句

    mysql增加列,修改列名.列属性,删除列语句 mysql修改表名,列名,列类型,添加表列,删除表列     alter table test rename test1; --修改表名 alter t ...

  6. iOS 聊天表情键盘

    具体思路 通过UIKeyboardWillChangeFrameNotification通知,监听键盘的改变,同时可以得到键盘的Frame和动画的持续时间, 新建键盘顶部工具条YSComposeToo ...

  7. iOS 新浪微博-5.0 首页微博列表

    首页显示微博列表,是微博的核心部分,这一章节,我们主要是显示出微博的列表. 导入第三方类库 pod 'SDWebImage', '~> 3.7.3' pod 'MJRefresh', '~> ...

  8. whu 643 Soul Artist(二维BIT 区间更新,单点查询)

    Soul Artis [题目链接]Soul Artis [题目类型]二维BIT &题解: 二维区间更新和一维相比,要容斥一下,更新一块区间就是更新4个点. 还有这个我先是写了2*n^2logn ...

  9. 第四章 CSS3概述

    1.CSS3新增常用选择器(1)结构性伪类选择器:root 文档根元素 :nth-child(n) 第N个子元素"first-child 第一个元素 :kast-child 最后一个子元素 ...

  10. TensorFlow的封装

    TensorFlow是比较底层的深度学习API,TF-Slim.TFLearn.Keras和TensorLayer均尝试简化TensorFlow/Theano,它们对TensorFlow/Theano ...